Page 1 of 1

Does copy function creates a temporary file?

Posted: Mon Jun 04, 2007 2:52 am
by stallingjohn
I use copy function of php to copy a file from source folder to destination folder.

And I have found that destination folder contains new file with filename as "filename .txt".

Notice there is a space between "filename" and ".txt". I am thinking that it is a temporary file created by copy function of php.

If i'm correct how can I delete such temporary files????
please reply me as fast as possible

Re: Does copy function creates a temporary file?

Posted: Mon Jun 04, 2007 3:05 am
by volka
How do you build the new file name in your script?
(to answer your question: No, I don't think it's a temporary file created by php or the os)

Posted: Mon Jun 04, 2007 3:14 am
by maliskoleather
PHP does genterate temporary files, but these are not placed in your script location, but rather somewhere relevant to PHP.

Its most likely that, as Fyed stated, that you have something wrong with your code.

Problem needs bit serious concerntation

Posted: Mon Jun 04, 2007 4:21 am
by stallingjohn
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[b]The script I use to copy file is:[/b]

Code: Select all

$shuffled_filename="done.txt";
$archive_filename="file-name.txt";
if (!copy("search/$shuffled_filename", "archive/$archive_filename")) 
		{
				die("<br />Failed to copy shuffled file to archive file...");
		}
And I have another script that reads "archive" folder. The script is as follows:

Code: Select all

$fnames=array();
$dir_path="archive";
if ($handle = opendir($dir_path)) 
	{
	   while (false !== ($file = readdir($handle)))
		{
	        $fnames[]=$file;
	    }
closedir($handle);
}
I print $fnames using following code:

Code: Select all

echo "<a href='archive/$fnames[$i]'>".$fnames[$i]."</a>";
when I echo like this it prints 2 files:

first is "file-name.txt" with link pointing to "archive/filename.txt" &

second is "file-name .txt" with link pointing to same "archive/filename.txt"

(note the space in second filename).


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jun 04, 2007 7:33 am
by superdezign
The error sounds like it occurring elsewhere. PHP doesn't just add characters to filenames... Try creating a different file and see if the same thing happens.
maliskoleather wrote:Its most likely that, as Fyed stated, that you have something wrong with your code.
That was definitely volka, though I see the similarity. :-p

Posted: Mon Jun 04, 2007 10:36 am
by maliskoleather
I dont see anything that would be causing the problem in this bit of code.
Do you have anything else that might be in your code that was involved in this? Old bits from when you were developing this function? Anything else that would write a file? I only ask, because im 99percent sure that PHP isnt just generating this extra file on its own, and for me it usually ends up being bits of rogue code that cause things like this.
superdezign wrote:That was definitely volka, though I see the similarity. :-p
pshht. I didnt get the name right, or even spell the wrong name right lol
I'd claim that I was drunk or something.. but its just not true :roll:
I guess that I need more caffeine.

Thanks for your answers

Posted: Wed Jun 06, 2007 2:00 am
by stallingjohn
Thanks for your most valuable answers:

For solving above I used trim()
and then used preg_replace to replace all the whitespace , newline char, tab char to "blank" in the filename of the file
now the problem is solved.