Welcome to WebmasterWorld Guest from 54.234.129.215

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php copy Not Working

     

adder

8:49 pm on May 9, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

I'm stuck with a short bit of code:

 copy($pngoldpth, $pngnewpth) or die("Unable to copy PNG.");
delete("$pngoldpth");
echo "PNG moved successfully";


The script dies even before it has a chance to get to the "die" bit :) I never get any output. Enabled all error messages - not a single warning or error message, just a blank screen.

I thought the folders had suddenly become not writable. Unlikely because my file upload script is working. Just in case tried this line:

echo ( is_writable($pngnewpth) ) ? 'writable' : 'not writable'; 


Also tried echoing the variables and I get the expected output from them. Is there something obvious that I'm missing? Please help.

g1smd

9:30 pm on May 9, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Look carefully at the value for the paths. Is it the full server path?

adder

1:58 pm on May 10, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



@g1smd, thank you, it was a very good point.

No, I was actually using a relative path (also tried the actual www url) how silly :)

I now changed the variables to the full path (i.e. /servername/local/home/myname/mydomain.com/mydir/) and it copied the file ok. But wait, I'm celebrating too early. The delete function is now not working. The error message is:

Fatal error: Call to undefined function delete() in /servername/local/home/myname/mydomain.com/mydir/test.php on line 13

Any ideas why?

adder

2:25 pm on May 10, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



oh, I actually replaced delete("$pngoldpth"); with unlink("$pngoldpth"); and it works fine. However, I'm still curious about the "delete" function! Is it not supported any more?

rocknbil

4:12 pm on May 10, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Was there ever one [php.net]?

This is a dummy manual entry to satisfy those people who are looking for unlink() or unset() in the wrong place.


You might find it more useful to use the DOCUMENT_ROOT environment variable where appropriate, making your app more portable:

$pngoldpth = $_SERVER['DOCUMENT_ROOT'] . "/mydir";
 

Featured Threads

Hot Threads This Week

Hot Threads This Month