Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Managing images

  1. #1
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Managing images

    I would like to manage images. Can you suggest me how to do this?

    As I have all images on server and I show them in rows, I need also to manage them.

    How to show all images in directory uploaded_images in table like:
    1 row:

    1 column: picture of image
    2 column: Filename
    Name (input field to change filename)
    Caption (input field to put Caption)
    Remove this image (checkbox to remove this image from server)

    I hope you can help

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    "Manage" them? That's very vague. Can you be more specific?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I would like to build system to read images.

    Images are on server in directory uploaded_images.

    As I would like to read them in my format with table as above, I do not know how to approach.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    PHP Code:
    <?php
    $directory 
    "uploaded_images";

    function 
    writeTable($dir) {
      echo(
    "<table>\n");
      
    $files;
      
    $d opendir($dir);
      while(
    $f=readdir($d)) {
        if(
    substr($f01) == ".") continue;
        echo(
          
    "\t<tr>\n" .
          
    "\t\t<td>" '<img src="' "$dir/$f'"></td>' "\n" .
          
    "\t\t<td>$f</td>\n" .
          
    "\t\t<td>\n" .
          
    "\t\t\t<form action=\"$PHP_SELF\" method=\"post\">\n" .
          
    "\t\t\t\t" '<input type="text" name="newname"><br>' "\n" .
          
    "\t\t\t\t" '<input type="text" name="caption">' "\n" .
          
    "\t\t\t\t" '<input type="checkbox" name="delete"><br>' "\n" .
          
    "\t\t\t\t" '<input type="hidden" name="filename" value="' $f '">' "\n" .
          
    "\t\t\t\t" '<input type="submit" value="Go">' "\n" .
          
    "\t\t\t</form>" .
          
    "\t\t</td>\n" .
          
    "\t</tr>\n"
        
    );
      }

      
    closedir($d);
      echo(
    "</table>\n");
      return 
    "";
    }

    if(!isset(
    $_POST['filename'])) die(writeTable("uploaded_images"));
    else if(!
    file_exists("$directory/" $_POST['filename']) || strpos($_POST['filename'], "./") != -1) die();

    $fn $directory "/" $_POST['filename'];

    if(
    $_POST['delete']) unlink($fn);
    else if(
    $_POST['newname']) rename($fn$directory "/" $_POST['newname']);
    else if(
    $_POST['caption']) {
      
    // What do you want done with this, sorry?
    }

    ?>
    Last edited by Twey; 04-19-2006 at 03:20 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I gives me error on line 99:
    Parse error: parse error, unexpected T_STRING in .../manageimages.php on line 99

    Line 99 is: "\t\t\t<form action=\"$PHP_SELF\" method="post">\n" .

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The "post" doesn't have escaped quotes.

    \"post\" <<use that.

  7. #7
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Now it works.
    I have just 3 questions:
    1. how to put text Remove image on the right? I have put span to give text on the right
    2. remove image and changing name of file (image) does not work
    3. If I put image management into my layout, it will not show all my code at the bottom.
    Do you know what is wrong?

    I enclose changed code:
    PHP Code:

     
    echo(
          
    "\t<tr class=manageimg>\n" .
          
    "\t\t<td>" '<img src="' "$dir/$f'"></td>' "\n" .
          
    "\t\t<td width=50></td>\n" .
          
    "\t\t<td>\n" .
          
    "\t\t\t<form action=\"$PHP_SELF\" method=\"post\">\n" .
          
    "\t\t\t\t" .'File name:'.$f.'<br><br>' "\n\n" .
          
    "\t\t\t\t" 'Name:<input type="text" name="newname"><br><br>' "\n\n" .
          
    "\t\t\t\t" 'Caption:<input type="text" name="caption"><br>' "\n" .
          
    "\t\t\t\t" '<span align="right"><input type="checkbox" name="delete">Remove this image<br><br><span>' "\n" .
          
    "\t\t\t\t" '<input type="hidden" name="filename" value="' $f '">' "\n" .
          
    "\t\t\t\t" '<input type="submit" value="Go"><br><br><br>' "\n" .
          
    "\t\t\t</form>" .
          
    "\t\t</td>\n" .
          
    "\t</tr>\n"
        
    ); 
    Last edited by toplisek; 04-19-2006 at 10:06 AM.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Not sure. Not sure if Twey coded those options into his code. Hmm... looks like he did though.. but they're pretty simple. Maybe you need more to them for them to work.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    With regard to unescaped quotes: Whoops. Edited.
    1. how to put text Remove image on the right?
    The right of what?
    2. remove image and changing name of file (image) does not work
    "Does not work" is really quite amazingly unhelpful. What happens?
    3. If I put image management into my layout, it will not show all my code at the bottom.
    Yes, that's because I used die() (this was only supposed to be an example, after all). You can use, instead of the block of code at the bottom:
    Code:
    if(!isset($_POST['filename'])) writeTable("uploaded_images");
    else {
      if(!file_exists("$directory/" . $_POST['filename']) || strpos($_POST['filename'], "./") != -1) die();
    
      $fn = $directory . "/" . $_POST['filename'];
    
      if($_POST['delete']) unlink($fn);
      else if($_POST['newname']) rename($fn, $directory . "/" . $_POST['newname']);
      else if($_POST['caption']) {
        // What do you want done with this, sorry?
      }
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how to put text Remove image on the right?

    I would like to do it on the right of table text Remove image

    "Does not work" is really quite amazingly unhelpful. What happens?

    When I click on remove image, it will not remove image. The same is if I would like to change name.

    Yes, that's because I used die()


    what should I change in code that it will show me also part after your code?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •