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.'); } ?> 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 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. 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. 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. ?> 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). 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. Link to comment https://forums.phpfreaks.com/topic/208142-simple-question/#findComment-1088040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.