Log in

View Full Version : Managing images



toplisek
04-18-2006, 05:50 PM
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 :)

Twey
04-18-2006, 05:57 PM
"Manage" them? That's very vague. Can you be more specific?

toplisek
04-18-2006, 06:11 PM
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.:)

Twey
04-18-2006, 07:26 PM
<?php
$directory = "uploaded_images";

function writeTable($dir) {
echo("<table>\n");
$files;
$d = opendir($dir);
while($f=readdir($d)) {
if(substr($f, 0, 1) == ".") 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?
}

?>

toplisek
04-19-2006, 06:53 AM
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" .

djr33
04-19-2006, 08:52 AM
The "post" doesn't have escaped quotes.

\"post\" <<use that.

toplisek
04-19-2006, 09:55 AM
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:



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

djr33
04-19-2006, 09:59 AM
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.

Twey
04-19-2006, 03:24 PM
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:
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?
}
}

toplisek
04-19-2006, 03:48 PM
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?

Twey
04-19-2006, 03:57 PM
I would like to do it on the right of table text Remove image
"\t\t\t\t" . '<label><input type="checkbox" name="delete">Remove image</label><br>' . "\n" .
When I click on remove image, it will not remove image. The same is if I would like to change name.Still not helpful. What exactly happens? You click the submit button, the page refreshes and...? Do you get any error messages?
what should I change in code that it will show me also part after your code?I've posted that.

toplisek
04-19-2006, 04:18 PM
"\t\t\t\t" . '<label><input type="checkbox" name="delete">Remove image</label><br>' . "\n" .
This will not put Remove text on the right

Still not helpful. What exactly happens? You click the submit button, the page refreshes and...? Do you get any error messages?

It is nor error, just page is blanc in my layout.


I've posted that.
Now it works also bottom page