How To Display Images Of A Directory

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

How To Display Images Of A Directory

apple
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);

?>

 

 

 


Reply

apacheNewbie
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 smile.gif

 

 

 


Reply

iGuest
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

Reply

optiplex
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

?>

Reply

magiccode9
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. php, display images in a directory, order - 12.20 hr back. (1)
  2. php, show images in a directory, order - 12.24 hr back. (1)
  3. php, display images in a folder, order - 12.40 hr back. (1)
  4. displaying all pictures in a directory - 15.09 hr back. (1)
  5. php display in directory - 22.92 hr back. (1)
  6. show images in directory - 45.39 hr back. (1)
  7. display images using php from directory - 47.28 hr back. (1)
  8. php display selected image from array - 47.78 hr back. (2)
  9. php display list of images with checkbox if checkbox is checked delete images - 62.11 hr back. (1)
  10. php code to display most recent image in sub directory - 62.21 hr back. (1)
  11. use scandir to show pictures to delete - 66.73 hr back. (1)
  12. php show image from directory - 72.53 hr back. (1)
  13. opendir display images - 94.96 hr back. (1)
  14. php code for displaying uploaded pictures from a directory - 97.79 hr back. (2)
Similar Topics

Keywords : display, images, directory

  1. Php Ftp Upload Form
    Adding User Directory to PHP Upload Form - Help (1)
  2. Unofficial Trap17 Hosted Members Directory
    (13)
    This is the Trap17 edition of the Hosted Members Directory. A script initially written by me for the
    Astahost forums. The script has gone through many a changes and is currently in version 4 which
    includes the following features:- > Listing of hosted members. > Listing of the websites of the
    hosted members. > Validation of the websites (whether the site is suspended, working or not not
    working, etc) > Save/Load result to/from database. > Multithreaded for faster operation. > Status
    messages, images and progress bar to keep you informed of the process. Link to the Scrip....
  3. How To Display The Latest Forum Post On Main Page
    (4)
    Hey does anyone know how to display the latest forum post on the main page of a website? I'm new
    to PHP and have no idea what to do. Thanks in advance!....
  4. My Code Doesnt Resize Large Images, Please Help.
    (2)
    Can someone please have a look at the following code, this uploads an image, and make it in 2 sizes,
    one size is max. 600 x 800, uploads to images folder and second 120 x 120 and uploads to thumbs
    folder. this script works fine, with normal size images, but if i try to upload large pics( for
    example, an image with dimension 2432 x 3300, it shows blank page, and uploads the original image
    without sizing to "image" folder, and doesnt make any small thumbnail... I hope u understand..
    Please someone help me, i shall be so thankful. session_start(); header("Cache-contro....
  5. Reading Files From Directory To Array, And Using $_get To Get Them
    Simple way to manage lot's of files (2)
    Some user posted a similar problem i had when i tried to figure out how to update content on my
    website in less work as possible. This is just part of the "big" plan i have for my site but it can
    be helpfull to you guys if you like FlatFile. I hope that mod's don't mind me posting the
    same code here and on their forums, couse if they do i'll delete it from their forums
    /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So
    here's the situation. Let's say you have a folder called 'myfilesdirectory' on your
    s....
  6. Display The Current Date/time
    With a simple PHP code (3)
    Use this code to display the current date and time. CODE <?php   $date =
    date('l dS \of F Y h:i:s A');   echo "$date"; ?>
    "l" would display the current day of the week such as Sunday. d displays the day of the month...
    such as 1 and S adds the appropriate suffix(st). /of simply displays the word "of". F displays the
    current month with no abbreviations while Y displays the four digit year(2007). "h" displays the
    current hour with leading zeros if necessary(Ex. 06 for 6 o'clock). "i" displays the m....
  7. Help Needed With Directory/file Listing Code Infinite Loop
    Made an infinite loop but why is this so? (5)
    Hi all ive got a small and simple (for the moment atleast /unsure.gif"
    style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> )file and directory
    listing script in php as follows CODE $dir = "."; $num = 0; $file =
    scandir($dir); while($file = scandir($dir)){     echo
    $file[$num];     echo "<BR>";     $num = $num + 1;     
    }; the concept is simple enough, the directory to start with is the current one, so scan this
    directory and wh....
  8. Display Random File In A Directory
    how to display a random file from a set directory. (9)
    hi, could someone please help me with this? I have some files in a directory and i want to know how
    i can randomly display link/s to one or more of the files in my directory for download. But it must
    not at any time display index.php which is also in the directory with the downloads. Thanks in
    advance for any help given /unsure.gif" style="vertical-align:middle" emoid=":unsure:" border="0"
    alt="unsure.gif" />....
  9. Changin My Phpnuke Directory...please Help
    (13)
    ok i wus fantastico to install my nuke...it asked me to give it a name for its directory so ive put
    down "nuke" so to get to my site ud have to go to www.boaw.trap17.com/"nuke" but now i want to
    change nuke into something else more related to the site...i was wondering if any1 can tell me the
    best way to do that...thanks....
  10. Display MySQL results in a Table
    question (8)
    hi all i know php and my sql i want to know how can show mysql result in this tabel for example :
    CODE <table cellpadding="0" cellspacing="0" width="200"
    height="151">     <!-- MSTableType="layout" -->     <tr>
            <td height="21" width="100" valign="top">1</td>
            <td height="21" width="100" valign="top">8</td>
        </tr>     <tr>         <td height="21" width="100" valign=&....
  11. Displaying Files Of A Directory
    (2)
    I want to display the contents of a directory.. i have the following code.. It gives the output in
    one column only... like file1 file2 file3 file4 . . . . . Since there are lot of files so this
    column gets very long..i want to display the x number of files in each column.. like if there are 22
    files.. then file 1 file 11 file 21 file 2 . file 22 file 3 .. . . . file 10
    file 20 This was just an example..I know it can be done by using but i dont know how to do it
    with loop. Please help me. QUOTE $dir = './'; $handle =....
  12. How To List Files In A Directory + Subdirectory And Then Use Them.
    (8)
    So lets say i have folders called friends and work in a folder called pics. how would i make a
    function that lists the files in those folderscalled images kinda like this: CODE
    $directory = "./" function listfiles($directory) { //here should go the
    script to list the files in those directories. so that i can continue to work with them. like for
    example if there were images it would list all  the images and i could write a script to make a
    thumb of them and then save it into a thumb folder(not asking for all of that). but how w....
  13. Directory Files Displaying
    (5)
    I have many files in a directory..I want to create a page , like A B C D E F ..... when some one
    click on A , it should display all the files starting from letter A , and when clicks on B , it
    should show all the files in that directory starting from B , and so on... I have no idea how to
    display the files of the directory iin that way. Kindly assist me......
  14. How To Sort Files Of A Directory using Php
    (11)
    The following code displays the files of folder...but they are displaced by the order of adding... i
    want to sord the files / folders alphabetically and sord by accending order and by decending
    order.. can some one help me. $path = ""; $dir_handle = @opendir($path) or
    die("Unable to open $path"); echo "Directory Listing of $path "; while($file =
    readdir($dir_handle)) { if(is_dir($file)) { continue; } else
    if($file != '.' && $file != '..') { echo " $fi....
  15. How I Can Display Forum Topic On Main Website ?
    (4)
    Suppose i have a website.. domain.com , and have phpbb forums on domain.com/forums.. And i want to
    display the new topics written in the forum on the main page of website...how i can do that.. ? for
    example ,I want to display this topic `? "domain.com/forums/viewtopic.php?t=16" how can i do
    that ?....
  16. <textarea> Tag Is Not Accepting Php Variable
    for display, although <Input> tag does accept it (2)
    I have a single page template which has a Form on it. Logic is to check for a valid Querystring and
    place the variables accepted from a form back into the form and re-display this form with error or
    acceptance messages. I'm sure everyone here has done this a million times. The Form accepts
    data from a user for First name, Last name, email address, and message-body named
    'note_wide' then re-displays the values into the Form, but for some reason, I can't get
    the value to display into a Textarea. Sample of the php code is as follows: first the good one:....
  17. Can You Add Images Into A Mysql Database?
    Using Php? (20)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  18. Help With Removing Files And Folders
    removing all files from a directory (4)
    Is there a function or a group of functions which I can use to delete all the files an folders in a
    directory? I've tried rmdir() but it complains that it can't remove it because there are
    files/folders in it. ....
  19. How To Create Images?
    (3)
    How can i create images (using php) of 128x128 by giving some types of background... and users can
    write text on the background... /blink.gif' border='0' style='vertical-align:middle'
    alt='blink.gif' /> QUOTE you can take example from the followinbg site:
    http://zedge.no/?side=navnelogo ....
  20. Directory Function
    - I need some help (1)
    Hey, I'm really in a jam. Here's whats happening, I have to post over 350 streaming WMA
    files on a server. But it would be nice to not have to script it out in HTML. And I know that in PHP
    you can set a directory or folder and PHP will place all the files out there. Would somone show me a
    way to do that? and please note where I must insert filenames, folder, ect.... So, I have tons of
    files that I need to have on the page, but scrpiting it takes long. Heres the page I'm working
    on: http://www.cbf-wa.org/sermons.php thanx so much....
  21. Securing Images
    (2)
    Just wondering if anyone's worked with securing images to avoid direct linking than just by
    obscuring the URL or using a .htaccess file. I briefly looked through the documentation and source
    for gallery and it looks like the images are stored under the web root, so anyone with a direct link
    can browse the images regardless of user privileges. I was thinking one way of doing this would be
    too store the images above the webroot directory so that visitor's can't navigate to them
    and having a php script that can read the image dir output the images by sending th....
  22. Including Php-made Images In A Page?
    (5)
    Say you have this script that makes an image, and you want to include it in another page. Would you
    just use ? I'd test it right now, but all my PHP image stuff is on my school's server,
    which is currently down.....
  23. Script: Phpbb Mod, Total Users Registered
    Display the total users anywhere on your site. (1)
    This is for phpBB V2+ It displays the total number of registered users anywhere you want. This file
    is called: phpbb-totalusers.php CODE <?php /** * ©2005 Craig lloyd. All rights reserved. * *
    Mod Title:   Total Registered Users * Author:      Craig Lloyd * Description: Shows
    total number of registered users * Release:     v1.2, 10th May 2005 *** * Demo:            
       http://www.toxicsims.co.uk/ (stats box) * Installation Level:  Easy *
    Installation Time:   1 minute * Files To Edit:       This one * Included Files....
  24. Vote Script Help
    images as a result? (1)
    I made a vote poll script, and it work fine with results in numers or %, but i want to show images
    as a result. Is that possible? For example like voting poll in this forum. I tried something but
    that couldnt work. Someone?....
  25. Getting List Of Directories And Files Using Php
    PHP Function for Directory and File List (6)
    is there a php function that lists the content of some folder.... example: /New folder new.txt
    left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
    style='vertical-align:middle' alt='rolleyes.gif' /> ....
  26. Refreshing Images
    (1)
    I've got a script that generates a graph by creating it as a .png file (I can't output the
    image directly to the browser because of the way I need to generate the data). This all works ok
    however, in order to keep the data managable I've set a limit so that it only displays 12 months
    data at a time. The problem I have is that when I click on the next button to display the next set
    of data, the graph remains the same until you refresh the browser. I've tried using unlink() to
    delete the image file forcing the script to re-generate it when the script is r....
  27. I Want A Php Code To Display The Most Popular...
    (6)
    I want a PHP code to display the most popular clicks/links on certain pages. Can anyone help?....

    1. Looking for display, images, directory

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for display, images, directory

*MORE FROM TRAP17.COM*
Similar
Php Ftp Upload Form - Adding User Directory to PHP Upload Form - Help
Unofficial Trap17 Hosted Members Directory
How To Display The Latest Forum Post On Main Page
My Code Doesnt Resize Large Images, Please Help.
Reading Files From Directory To Array, And Using $_get To Get Them - Simple way to manage lot's of files
Display The Current Date/time - With a simple PHP code
Help Needed With Directory/file Listing Code Infinite Loop - Made an infinite loop but why is this so?
Display Random File In A Directory - how to display a random file from a set directory.
Changin My Phpnuke Directory...please Help
Display MySQL results in a Table - question
Displaying Files Of A Directory
How To List Files In A Directory + Subdirectory And Then Use Them.
Directory Files Displaying
How To Sort Files Of A Directory using Php
How I Can Display Forum Topic On Main Website ?
<textarea> Tag Is Not Accepting Php Variable - for display, although <Input> tag does accept it
Can You Add Images Into A Mysql Database? - Using Php?
Help With Removing Files And Folders - removing all files from a directory
How To Create Images?
Directory Function - - I need some help
Securing Images
Including Php-made Images In A Page?
Script: Phpbb Mod, Total Users Registered - Display the total users anywhere on your site.
Vote Script Help - images as a result?
Getting List Of Directories And Files Using Php - PHP Function for Directory and File List
Refreshing Images
I Want A Php Code To Display The Most Popular...
advertisement



How To Display Images Of A Directory



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE