Displaying images
Moderator: General Moderators
Displaying images
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!
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!
Quick answer:
Start by using opendir() to get all images... You should manage from that page's usercomments.
Start by using opendir() to get all images... You should manage from that page's usercomments.
Uhm, yah.
You can use more than one cookie...
setvookie()
And, read the text in my signature.
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
*/
?>There are examples on the opendir-manual-pages. This is what I have done once:
Customize to fit your needs...
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 htmlcould 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>#1: You should add more quotes around the cookie variable...
#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;
#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
// bad
$dir = $_COOKIE[user];
// better
$dir = $_COOKIE['user'];Code: Select all
if (($file != ".") and ($file != "..")) {
// ... show image ...
}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-dircan 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
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
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