jakebur01 Posted March 6, 2009 Share Posted March 6, 2009 to delete an image, could i do something like this? echo"<a href=\"view_images.php?delete=urlencode($file)\">delete image</a> then if (isset($_GET['delete'])) { $delete_image=c:/images/urldecode($_GET['delete']); unlink("delete_image"); } Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/ Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 to delete an image, could i do something like this? What makes you think that you can't do that? Have you tried it? Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778268 Share on other sites More sharing options...
jakebur01 Posted March 6, 2009 Author Share Posted March 6, 2009 my image names have underscores and periods in it. I read: Returns a string in which all non-alphanumeric characters except -_. I want to do this the best way. I didn't know if urlencode would be the best option. Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778271 Share on other sites More sharing options...
JonnoTheDev Posted March 6, 2009 Share Posted March 6, 2009 Yes you can, however your syntax has more bugs than the amazon basin. Here: <?php echo "<a href=\"view_images.php?delete=".urlencode($file)."\">delete image</a>"; if(strlen($_GET['delete'])) { $delete_image = "c:/images/".urldecode($_GET['delete']); unlink($delete_image); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778285 Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 You should also do some more checks on the file name because someone could easily inject something in your URL. Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778289 Share on other sites More sharing options...
jakebur01 Posted March 6, 2009 Author Share Posted March 6, 2009 it is all under if (isset($_SESSION['valid_user'])) { } Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778292 Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 it is all under if (isset($_SESSION['valid_user'])) { } Ok, if you trust your users then that's fine. Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778293 Share on other sites More sharing options...
jakebur01 Posted March 6, 2009 Author Share Posted March 6, 2009 Where would these errors be reported to? Would they go to my web host? Is there a way to have them e-mailed to me? Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778298 Share on other sites More sharing options...
JonnoTheDev Posted March 6, 2009 Share Posted March 6, 2009 what errors? Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778314 Share on other sites More sharing options...
jakebur01 Posted March 6, 2009 Author Share Posted March 6, 2009 Does ini_set ("display_errors", "1"); error_reporting(E_ALL); log errors when someone is trying to inject stuff into url? How will you know when they are trying to do that? Isn't that what that is for? I read a little bit on ini_set ("display_errors", "1"); error_reporting(E_ALL); but I was having trouble understanding exactly how it works. - Jake Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778359 Share on other sites More sharing options...
JonnoTheDev Posted March 6, 2009 Share Posted March 6, 2009 Haha That is Maqs footer on all blog posts not code for you to add to your script! Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778368 Share on other sites More sharing options...
jakebur01 Posted March 6, 2009 Author Share Posted March 6, 2009 Ha Ha.... my head way starting to get foggy and his footer looked as though it were part of the post. Sorry.... Thank you for all your help. It is working great now. Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778374 Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 Ha Ha.... my head way starting to get foggy and his footer looked as though it were part of the post. Sorry.... Thank you for all your help. It is working great now. Hehe, yeah I leave it there cause I reference it a lot. Did you get errors when you added that in your code? Quote Link to comment https://forums.phpfreaks.com/topic/148245-solved-delete-an-image/#findComment-778383 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.