ayok Posted November 16, 2007 Share Posted November 16, 2007 Hi, I have a question. I have some php scripts to upload images and delete it. But if I delete the image I only delete the image's data in the database, and the image still remains in the folder. My question is, how can I remove the image from the image folder? Thank you, ayok Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 unlink() http://us3.php.net/unlink Quote Link to comment Share on other sites More sharing options...
ayok Posted November 16, 2007 Author Share Posted November 16, 2007 Hey, thanks pocobueno. ayok Quote Link to comment Share on other sites More sharing options...
ayok Posted November 17, 2007 Author Share Posted November 17, 2007 Hi, I have difficulty to set up the code. What I try to do is to unlink 2 images (same name) in different folder. This is my delete.php <?php include "../dbconnect.php"; $delete="DELETE from product WHERE id='$id'"; $result=mysql_query($delete); if($result) { header("location:index.php"); } else { echo "Delete process failed"; echo "<a href=index.php>Try again</a><br>"; echo "<a href=logout.php>Logout</a><BR>"; } ?> I've tried to add this code: $image = "SELECT image FROM products WHERE id = '$id'"; unlink('images/$image); unlink('images/thumbnail/$image); But it doesn't work. Could anybody help me? Thanks, ayok But Quote Link to comment Share on other sites More sharing options...
0x00 Posted November 17, 2007 Share Posted November 17, 2007 Silly question, but are you getting the 'image' name before deleting the entry, e.g. why didn't you just show the new code? After that check permissions, (e.g. if you created the images you should be able to delete them!) refs: http://us3.php.net/manual/en/function.fstat.php, see 'mode' http://us3.php.net/manual/en/function.chmod.php Quote Link to comment Share on other sites More sharing options...
ayok Posted November 19, 2007 Author Share Posted November 19, 2007 All right, I can now unlink the image files from the image folder in localhost. But when I test it on web server, i keep getting this error: Warning: unlink() [function.unlink]: http does not allow unlinking in /home/mywebcom/HTML/products/admin/delete.php on line 8 I even set the permission to 777, but i still get this error. How can I solve this? Thank you, ayok Quote Link to comment Share on other sites More sharing options...
ayok Posted November 20, 2007 Author Share Posted November 20, 2007 nobody? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 your web server does not allow the unlink command to run maybe because of some security issue, check up with your hosting provider Quote Link to comment Share on other sites More sharing options...
ayok Posted November 20, 2007 Author Share Posted November 20, 2007 Thanks Rajiv, Hmm, it doesn't depend on the chmod setting? cheers, ayok Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 20, 2007 Share Posted November 20, 2007 yeah it also depends on the chmod setting. If you dont have permission to write to a folder then you wont be able to delete a file. I think it should be set to 777 but i am not 100% sure. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 well looking at the errors it says the http does not allow unlinking that means apache does not allow unlinking this must be some security setting on your server that does not allow some commands to be executed Quote Link to comment Share on other sites More sharing options...
ayok Posted November 20, 2007 Author Share Posted November 20, 2007 But it's kind of weird, because i made an upload script where I can put an original image, then create two smaller images in different folders, and then in the same script, I am able to unlink the original image from the folder. So how come I couldn't unlink those two smaller images? thanks, ayok Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.