Agent Posted July 19, 2010 Share Posted July 19, 2010 So I am just starting to learn PHP this summer but have hit a road block. It is probably something simple I am forgetting about. So basically delete.php?file=123.jpg 123.jpg is in 'files/' from where the script is. <?php $deletefile = $_GET['file']; if (file_exists(files/$deletefile)) { unlink('files/$deletefile'); } else { echo ('We had a problem completing your request.'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/ Share on other sites More sharing options...
YourNameHere Posted July 19, 2010 Share Posted July 19, 2010 So I am just starting to learn PHP this summer but have hit a road block. It is probably something simple I am forgetting about. So basically delete.php?file=123.jpg 123.jpg is in 'files/' from where the script is. <?php $deletefile = $_GET['file']; if (file_exists(files/$deletefile)) { unlink('files/$deletefile'); } else { echo ('We had a problem completing your request.'); } ?> I didn't see an actual question in there but I saw an issue with your code... this line: if (file_exists(files/$deletefile)) { should be if (file_exists('files/'.$deletefile)) notice the ''. ? You must encapsulate and concatenate. Edit: Same thing with the unlink function Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088012 Share on other sites More sharing options...
Agent Posted July 19, 2010 Author Share Posted July 19, 2010 So I am just starting to learn PHP this summer but have hit a road block. It is probably something simple I am forgetting about. So basically delete.php?file=123.jpg 123.jpg is in 'files/' from where the script is. <?php $deletefile = $_GET['file']; if (file_exists(files/$deletefile)) { unlink('files/$deletefile'); } else { echo ('We had a problem completing your request.'); } ?> I didn't see an actual question in there but I saw an issue with your code... this line: if (file_exists(files/$deletefile)) { should be if (file_exists('files/'.$deletefile)) notice the ''. ? You must encapsulate and concatenate. Thank you, I am still learning and guess I didn't get to that point. Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088013 Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2010 Share Posted July 19, 2010 If you were doing this on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, all the errors that php detects will be reported and displayed. You will save a ton of time. There would be a error for the problem that YourNameHere pointed out and there would be an error when the unlink() statement executes as well because you put single-quotes around the string in it and php variables are not replaced with their value when enclosed in single-quotes, but they are when enclosed in double-quotes. Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088015 Share on other sites More sharing options...
YourNameHere Posted July 19, 2010 Share Posted July 19, 2010 At the top of the .php page, <?php error_reporting(2); // Should help you debug these simple errors. ?> Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088016 Share on other sites More sharing options...
trq Posted July 19, 2010 Share Posted July 19, 2010 At the top of the .php page, <?php error_reporting(2); // Should help you debug these simple errors. ?> More like error_reporting(30719), or better still, the easy to read version. error_reporting(E_ALL). Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088028 Share on other sites More sharing options...
Agent Posted July 19, 2010 Author Share Posted July 19, 2010 Thank you guys, I busted out the PHP for dummies book and have got quite allot done. I might get the hang of this eventually. Quote Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088040 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.