|
|
|
|
![]() ![]() |
Feb 24 2008, 02:03 AM
Post
#1
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 31 Joined: 9-August 06 Member No.: 28,049 |
I am trying to do a simple thing. I want to display all the images of a directory on a single page with the checkbox next to each image, so that i can select multi images and i can delete selected images.
Following few lines of code display the images of a directory.. i need help to put the check boxes with each image. and I dont understand how can i select multi images with check box and then delete them. I hope someone can help. thanks. CODE <?php $path = "./"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<img src='$file' alt='$file'><br />"; } closedir($dir_handle); ?> |
|
|
|
Feb 24 2008, 09:19 AM
Post
#2
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 29 Joined: 23-November 06 Member No.: 33,877 |
I would use file name as check box identifier. So first, we will add checkbox in your code
CODE <?php $path = "./"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<input type=CHECKBOX name=$file>"; echo "<img src='$file' alt='$file'><br />"; } closedir($dir_handle); ?> That is, now you have images with check box beside them. In order to delete the chosen images, you need to capture which checkbox is selected. This is the example of how to know which check box is checked (assuming, you are using POST method to submit the form using delete button): CODE <?php $path = "./"; $dir_handle = @opendir($path) or die("Unable to open folder"); //We list the name of the files again, since the name of the checkbox is the same with the name of the file while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; if(isset($_POST[$file])){ $checkbox = $_POST[$file]; if($checkbox == on) { //checkbox is selected //Delete the file if(!unlink($file)) die("Failed to delete file"); } } ?> Hopefully it helps This post has been edited by apacheNewbie: Feb 24 2008, 09:20 AM |
|
|
|
Jun 26 2008, 09:22 AM
Post
#3
|
|
|
Hail Caesar! ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
PHP display a column in vertical way
How To Display Images Of A Directory HI, I'm new in php, if anyone can help me, I would really appreaciate it, my problem is, iwant to display a column or one column in vertical way like this: 1 2 3 4 5 6 Not the usual way like this: 1 2 3 4 5 6 Hoping for anyones reply. Many thanks in advance. -reply by marc |
|
|
|
Jun 26 2008, 05:36 PM
Post
#4
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: [HOSTED] Posts: 40 Joined: 26-June 08 Member No.: 64,213 |
This should help, not sure though :
CODE <?php
/* by optiplex */ $path = "./"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if(ereg("(.*)\.(jpg|bmp|jpeg|png|gif)", $file)){ echo "<img src='$file' alt='$file'><br />"; } } closedir($dir_handle); - optiplex ?> This post has been edited by optiplex: Jun 26 2008, 05:36 PM |
|
|
|
Jun 29 2008, 02:10 PM
Post
#5
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 165 Joined: 1-November 05 From: SATA II Member No.: 13,683 |
This may be help a bit.
CODE <?php $file_ary = isset($_POST['rfile']) ? $_POST['rfile'] : array(); /** * At first visit, show the file list */ if (empty($file_ary)) { $image_path = dirname(__FILE__) . '/images'; $dir_handle = null; if (!($dir_handle = opendir($image_path))) { //trigger_error('error, path not found'); return; } $html = '<html><form method="post">'; $file = readdir($dir_handle); while ($file) { $html .= "{$file}<input type=\"checkbox\" name=\"rfile[]\" value=\"{$file}\" /><br />\r\n"; $file = readdir($dir_handle); } closedir($dir_handle); $html .= '<input type="submit" name="submit" value="Submit" />'; $html .= "</form></html>"; echo $html; } /** * Now, we have list, display it or do anything you need to .. */ if (!empty($file_ary)) { echo '<pre>'; print_r($file_ary); echo '</pre>'; } ?> You may also check out this svn repository for updates when available https://opensvn.csie.org/freescript |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 08:32 AM |