Page 1 of 1
Displaying images
Posted: Sun Oct 26, 2003 7:59 pm
by nick2
Hello.. quick question..
how would I display all images of a folder ?
I'm putting each image into a checkbox form.. so you can pick the one you want to remove..
so <p><input type="checkbox" name="C1" value="ON"></p>
anyway help would be great thanks!
Posted: Sun Oct 26, 2003 8:05 pm
by JAM
Quick answer:
Start by using
opendir() to get all images... You should manage from that page's usercomments.
Posted: Sun Oct 26, 2003 8:07 pm
by nick2
thank you!
Posted: Sun Oct 26, 2003 8:19 pm
by nick2
Hey I need to save the login id they type into a cookie but I am already setting cookies so I don't tink I can set two..
any suggestions?
see I need the login id to know what folder their images are in.
lol
thanks
Posted: Sun Oct 26, 2003 8:31 pm
by JAM
Uhm, yah.
You can use more than one cookie...
setvookie()
And, read the text in my signature.
Code: Select all
<?php
// an example from the manual...
// set the cookies
setcookie ("cookie[three]", "cookiethree");
setcookie ("cookie[two]", "cookietwo");
setcookie ("cookie[one]", "cookieone");
// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
echo "$name : $value <br />\n";
}
}
/* which prints
three : cookiethree
two : cookietwo
one : cookieone
*/
?>
Posted: Sun Oct 26, 2003 8:40 pm
by nick2
Thanks again but how would I go about making a loop to display all images?
i'm new at this..
Posted: Sun Oct 26, 2003 8:52 pm
by JAM
There are examples on the opendir-manual-pages. This is what I have done once:
Code: Select all
$dir = './images'; // set directory
$dh = opendir($dir); // open it for reading
echo '<select name="image">'; // html
while (($file = readdir($dh)) !== false) { // loop files
if (substr($file,-4) == '.jpg') { // just fetch .jpg images...
echo "\n".' <option>' . $file .'</option>'; // each image html
}
}
echo '</select>'; // end html
Customize to fit your needs...
Posted: Sun Oct 26, 2003 9:12 pm
by nick2
could you please tell me whats wrong? i'm getting very confused..
Code: Select all
<html>
<head>
<title>Slices.net - Manage pictures</title>
</head>
<body>
<table border="1" width="100%" bordercolor="#000000" cellspacing="1" cellpadding="0" bordercolorlight="#000000" bordercolordark="#000000">
<tr>
<td width="100%">
<p align="center"><font size="2"><font color="#FF0000"><a href="addp.php">Add</a>
a picture </font>/ <font color="#FF0000"><a href="removep.php">Remove</a></font>
<font color="#FF0000">
selected</font></font></td>
</tr>
<tr>
<td width="100%"> </td>
</tr>
</table>
<form method="POST" action="removep.php">
<? $dir = $_COOKIE[user];
$dh = opendir($dir); // open it for reading
while (($file = readdir($dh)) !== false) { // loop files
echo "<img border="0" src="$file">"; // each image html
}
?>
</form>
</body>
</html>
Posted: Sun Oct 26, 2003 9:24 pm
by nick2
for some reason its displaying 3 broken links.. :/
even thought theres 1 image.
Posted: Sun Oct 26, 2003 9:25 pm
by JAM
#1: You should add more quotes around the cookie variable...
Code: Select all
// bad
$dir = $_COOKIE[user];
// better
$dir = $_COOKIE['user'];
#2: readdir() also 'sees' the . (present dir) and .. (parent dir) in the catalogue, so you need to skip those with an if-clause. (as they are no images, hence can't be displayed). I used substr() to check if the $file ended with .jpg rahter than;
Code: Select all
if (($file != ".") and ($file != "..")) {
// ... show image ...
}
#3: Have in mind that you are trying to echo
http://www.example.com/filename.jpg rather than
http://www.example.com/username/filename.jpg
Code: Select all
// change...
echo "<img border="0" src="$file">"; // each image html
// to...
echo "<img border="0" src="".$_COOKIE['username']."/".$file."">"; // each image html, added username-dir
Posted: Sun Oct 26, 2003 10:30 pm
by nick2
can you help with this? i'm trying to make this drop down menu work.. i want when u select the image in the drop down menu it will do post removep.php ... but for some reason it displays drop down menu then on right of that just a text box..
heres my code
Code: Select all
$dir = $_COOKIE[user];
$dh = opendir($dir); // open it for reading
echo '<form><select name="delete">'; // html
while (($file = readdir($dh)) !== false) { // loop files
if (substr($file,-4) == '.jpg') { // just fetch .jpg images...
echo "\n".' <option>' . $file .'</option>'; // each image html
}
}
echo '<p><input type="submit" value="Delete" name="B1"></p>';
echo '</select></form>'; // end html
also i don't want it to just display .jpg.. i removed that but it then displays . and ... in the drop down menu aswell.. ahhhh