Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use the below code to delete images in my admin panel. I saved the file as <code>deletephoto.php</code>. Note that this script works without login. You need to make some changes to fit your use case</p> <pre><code>&lt;form method="post" action="deletepho.php"&gt; &lt;center&gt; &lt;input type="submit" value="Delete" name="Delete"&gt; &lt;/center&gt; &lt;?php \\lets assign the folder name in $title \\You can assign any name $title= "test"; \*$directory corresponds to whole path. Edit to your preference. (i assume u store your images in directory named "images") */ $directory = "$title/images"; \\The array specifies the format of the files $allowed_types=array('jpg','jpeg','gif','png'); $file_parts=array(); $ext=''; $title=''; $i=0; $dir_handle = @opendir($directory) or die("There is an error with your image directory!"); while ($file = readdir($dir_handle)) { if($file=='.' || $file == '..') continue; $file_parts = explode('.',$file); $ext = strtolower(array_pop($file_parts)); $title = implode('.',$file_parts); $title = htmlspecialchars($title); $nomargin=''; if(in_array($ext,$allowed_types)) { if(($i+1)%4==0) $nomargin='nomargin'; echo' &lt;div id="picture"&gt; &lt;img src="'.$directory.'/'.$file.'" width="150" height="150"&gt;&lt;br&gt; Select &lt;input type="checkbox" value="'.$directory.'/'.$file.'" name="imgfile[]"&gt; \* I specified input name as an array . So that we can store in an array and delete it.*/ &lt;/div&gt;'; } $i++; } closedir($dir_handle); \\Now we have the list of images within form elements ?&gt; &lt;/form&gt; </code></pre> <p>Now here is the actual code to delete the photos. I saved it as <code>deletepho.php</code>.</p> <pre><code>$file = $_REQUEST['imgfile']; $num_files=count($file); for($i=0;$i&lt;$num_files;$i++) { unlink ("$file[$i]"); } echo "Images successfully deleted.Go &lt;a href='deletephoto.php'&gt;back&lt;/a&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload