Does copy function creates a temporary file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stallingjohn
Forum Newbie
Posts: 6
Joined: Mon Apr 23, 2007 2:16 am

Does copy function creates a temporary file?

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Does copy function creates a temporary file?

Post 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)
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post 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.
stallingjohn
Forum Newbie
Posts: 6
Joined: Mon Apr 23, 2007 2:16 am

Problem needs bit serious concerntation

Post 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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post 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.
stallingjohn
Forum Newbie
Posts: 6
Joined: Mon Apr 23, 2007 2:16 am

Thanks for your answers

Post 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.
Post Reply