|
Answer» hi, in my application i would upload a file to a certain directory then after i would be able to DELETE it but then a got a warning
Warning: unlink(mydirectry/file.csv) [function.unlink]: Permission denied in C:\xampp\htdocs\dum\fac\submit_successfullyg.php on line 84
heres my code
Code: [Select] $myfile = 'mydirectry/file.csv'; if(!file_exists($myfile)) { echo "File not found. Make sure you specified the correct path.\n"; exit; } else unlink($myfile);The web server must have set the read/write permissions for that file or folder.
On a linux server you would use 0777 chmod. Something like (not tested) ... Code: [Select]chmod($myfile, 0777); unlink($myfile); Also note if there's more folders/files under a folder your using 'unlink' on, ensure you create a recursive delete method. Since it's only one file you shouldn't need to worry about this. well i'm using windows 7 and XAMPP, and i try 0777 and 777 but it didn't work.I've never used XAMPP before, chmod is a linux command probably won't work in your case. Have you setup a webserver on Windows 7 to host or is this just a temporary testing thing?oh i see, i just using windows 7 as a testing thing but probably it would be host in linux i think!!Yep, you'd probably be hosting on Linux so it shouldn't be an issue.
As an FYI, I searched on the PHP.net site and saw the following comment:
Quote Under Windows System and Apache, denied access to file is an usual error to unlink file. To delete file you must to change file's owern. An example:
<?php chown($TempDirectory."/".$FileName,666); //Insert an Invalid UserId to set to Nobody Owern; 666 is my standard for "Nobody" unlink($TempDirectory."/".$FileName); ?> Not sure if that works. Anywhoo, is just an FYI.Quote from: http://www.php.net/manual/en/function.unlink.php#85938To ANYONE who's had a problem with the permissions denied error, it's sometimes caused when you try to delete a file that's in a folder higher in the hierarchy to your working directory (i.e. when trying to delete a path that starts with "../").
So to work around this problem, you can use chdir() to change the working directory to the folder where the file you want to unlink is located.
Code: [Select]<?php $old=getcwd();//Savethecurrentdirectory chdir($path_to_file); unlink($filename); chdir($old);//Restoretheoldworkingdirectory ?> HY. I runned into that *CENSORED* problem too. And after days of searching I finally found this software: *SPAM*.
It's GREAT. You can find it here: http://www.deletelongfile.com
|