JesseToxik Posted June 12, 2013 Share Posted June 12, 2013 I am trying to write a script on a hidden page to delete images in my gallery(I am not using databases). I tried writing this code(to delete both the icon and large version of the image) but it failed. What did I do wrong? <?php if (array_key_exists('delete_file', $_POST)) { $filename = $_POST['delete_file']; if (file_exists($filename)) { unlink($filename); echo 'File '.$filename.' has been deleted'; } else { echo 'Could not delete '.$filename.', file does not exist'; } } $large = glob("/images/main/large/*"); $icons = glob("/images/main/icons/*"); foreach($large as $lrg && $icons as $icon) { echo "<div class='divimages'>"; echo '<img src="'.$lrg.'"/><br>'; echo '<img src="'.$icon.'"/>'; echo '<form method="post">'; echo '<input type="hidden" value="'.$lrg.'" name="delete_file" />'; echo '<input type="hidden" value="'.$icon.'" name="delete_file" />'; echo '<input type="submit" value="Delete image" />'; echo '</form>'; echo "</div>"; } ?> Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted June 12, 2013 Share Posted June 12, 2013 Should show you why its failing: error_reporting(-1); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
JesseToxik Posted June 12, 2013 Author Share Posted June 12, 2013 My page won't even load. All I get is Server errorThe website encountered an error while retrieving http://cronanpilotcar.byethost33.com/inc/scripts/ImageDelete.php. It may be down for maintenance or configured incorrectly. Here are some suggestions:Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 12, 2013 Share Posted June 12, 2013 you have got a fatal parse/syntax error on line 13. if you had stated in the first post in the thread what result you were getting, the first reply wouldn't have been wasted. you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini to show fatal parse/syntax errors in your main file. as to what is causing that error, you need to research the syntax for a foreach(){} statement. a foreach(){} statement loops over ONE array. 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.