Jump to content

[SOLVED] delete multiple files


steviez

Recommended Posts

Well give your check boxes an array name like 'remove[]'

 

Then when the form is submitted, use $_POST['remove'] to get all the values of all check boxes selected. Then loop through the $_POST['remove'] array.

 

If you're having trouble already, learn PHP first. Best advice I can give.

Link to comment
Share on other sites

Well give your check boxes an array name like 'remove[]'

 

Then when the form is submitted, use $_POST['remove'] to get all the values of all check boxes selected. Then loop through the $_POST['remove'] array.

 

If you're having trouble already, learn PHP first. Best advice I can give.

 

thanks for that, im currently trying to learn php thats why i need help.

 

I have done what you said and when i use the print_r function i get this:

 

Array ( [0] => on [1] => on [2] => on [3] => on [4] => on [5] => on ) 

 

how do i make it so i can delete my files from that?

 

thanks

Link to comment
Share on other sites

Yup, but you don't need the reference next to $value.

 

this is my code so far and it wont work:

 

<?php
## Delete multiple file ##
if(isset($_POST['file_option']) && $_POST['file_option'] == 'delete')
{
    // Get file path and file id
    $path = $setting['upload_path'];


// Loop through data and delete files
$files_array = array($_POST['delete']);
    foreach ($files_array as $files) 
{
    // Query database to get file info
    $query_file = @mysql_query("SELECT * FROM uploads WHERE id = '".$files."' 
                                                      AND upload_owner = '".$_SESSION['userid']."' LIMIT 1");
	$file = @mysql_fetch_array($query_file);

	// Delete file from server
    @unlink($path.$file['image_name']);

	// Delete thumb from server
    @unlink($path.$file['image_thumb']);

	// Delete file from database
    @mysql_query("DELETE FROM uploads WHERE id = '".$files."' AND upload_owner = '".$_SESSION['userid']."' LIMIT 1");

    // Redirect
    @header("Location:" . $url->url_base . '/myfiles');
}
}
?>

 

any ideas?

Link to comment
Share on other sites

What's the HTML form? Also debug stuff, can you echo $path?

 

<div class="right_side" id="right_side">
    <form method="post" action="{$url->url_base}/myfiles" name="file_options">
    <div class="file_options">
      <select name="file_option">
        <option value="" selected="selected">-- Selected Image Options --</option>
	<option value="delete">Delete image(s)</option>
	<option value="">-- Move Image To --</option>
	<option value="1">folder one</option>
      </select>
      <input type="submit" value="Go" />
      <input type="button" value="Upload" />
      <div style="margin-top:8px;"><strong>Select:</strong> <a href="javascript:;" onclick="javascript:selectToggle(true, 'file_options');">All</a>, <a href="javascript:;" onclick="javascript:selectToggle(false, 'file_options');">None</a></div>
 </div>

{if $num_results == 0}
<div align="center" style="margin-top:10px;">
     <div class="info">
 You currently have no uploaded images. 
 </div>
 </div>

 {else}
 <style type="text/css">{literal}
 input.cb {position:absolute; margin-top:4px;}
 </style>{/literal}
 <div style="margin-top:10px;">
<table border="0" cellpadding="6" cellspacing="6">
  <tbody>
    <tr> 
{foreach name=images item=row from=$results}
      <td>
  <div class="img" id="img_{$row.id}" style="text-align:center;margin:0 auto;">
	  <input type="checkbox" class="cb" name="delete[]" value="{$row.id}" />
	  <a href="{$url->url_base}/viewer/{$row.id}/{$row.image_name}"> 
	  <img src="./uploads/{$row.image_thumb}" alt="" class="image_thumb" id="{$row.id}" />
	  </a> 
	  </div>
          <div style="clear:both; text-align:left"></div>
	</td>
      {if $smarty.foreach.images.iteration mod $columns eq 0} </tr>
  {/if}
  {/foreach}
  </tr>
  </tbody>
</table>
</td>
</tr>
</table>

</div>
  </form>
  {/if}
</div>

Link to comment
Share on other sites

Your form doesn't even have name attribute for delete. Exactly, how does your code supposed to work. I have no idea what that HTML form is doing with that PHP code. They're like 2 different things.

 

fixed it! the form was 100% fine it was the following php code:

 

$files_array = array($_POST['delete_file']);

 

should be

 

$files_array = $_POST['delete_file'];

 

all fixed now :) thanks for your help.

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.

Guest
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.