Jump to content

What did I do wrong?


Recommended Posts

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?

if (array_key_exists('delete_file', $_POST)) {
  $filename = $_POST['delete_file'];
  if (file_exists($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>";  

Link to comment
Share on other sites

My page won't even load.

All I get is 

Server error
The 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:
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.