Click to See Complete Forum and Search --> : creating and writing to files, inside a sub-folder


diamonds
11-25-2003, 06:51 PM
I know the solution is quite simple, but iv'e been working my brain for too long now.

I want PHP to create a folder, if it doen't alredy exist.
that part works fine. than i want it to copy a file from one place to inside the created folder--thats where the errors are:

Warning: copy(/new_script/index2.php ): failed to open stream: No such file or directory in .../copy.php on line 26

line 26:
copy('http:// ... files/'.$file,'/new_script/'.$file);
Yes, there really is somthing replaced by the ' ... '
yes, fopen-wrapper is enabled.
I have tried it without the start slash for the 2nd property, too.

any help is good.

PunkSktBrdr01
11-25-2003, 10:08 PM
You have a comma instead of a period after the first $file.

diamonds
11-26-2003, 01:44 PM
basicly, the variables replaced with their values are
copy("http://SERVER/files/file1.txt","/new_script/index1.php")

I don't think you see there is a comma after the first $file

this is exactly how the text appears in the main post:
copy('http:// ... files/'.$file,'/new_script/'.$file);

diamonds
11-27-2003, 11:53 AM
ive narrowed it down to a totally freak variable bug.


copy($server.'files/'.$s.$ext,realpath('new_script'.'/index1.txt')); //totally works

copy($server.'files/'.$s.$ext,realpath('new_script'.$file)); //totally gives an error

echo $file;//prints '/index1.txt'


the variable $file is equel to '/index1.php' and, using it, it gives an error. however , replacing it with its string equivelant, '/index1.txt', it works fine.

do you think this is a bug in PHP?

PunkSktBrdr01
11-28-2003, 11:19 AM
Not sure if it would make a difference, but try adding the slash to the "new_script" part and removing the slash from the file name.