Jump to content

Recommended Posts

ok I got the images to upload to the directory on the server. now I got some code to try to display the image on the same page after you submit it to the directory. so it's like, submit form-> images goes in server directory->echoes back out on same page but just above the upload form. please any help greatly appreciated.

thanks.

 

here is the code so far.

 

<?php
// An Example about listing Images.
$dir = "uploads/";
$odir = opendir($dir);
while($file = readdir($odir)){
if(filetype($file) == "image/JPEG") {
echo $file;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>UPLOAD YOUR PORTFOLIO AND PRICES</p>
<p> </p>
<p>  <form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form></p>
</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/252971-displaying-images-from-a-directory/
Share on other sites

thank you for that. I took some code from "uploader.php" and put it all in the form page , so the page should both upload it and display the image on the page reload. doesn't work though. nice idea though. LOL. please any help again appreciated. thanks.

 

<?php
// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
// An Example about listing Images.
$dir = "uploads/";
$odir = opendir($dir);
while($file = readdir($odir)){
if(filetype($file) == "image/JPEG") {
echo '<img src="' . $file . '" />';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>UPLOAD YOUR PORTFOLIO AND PRICES</p>
<p> </p>
<p>  <form enctype="multipart/form-data" action="upload_gallery.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form></p>
</body>

</html>

I think I am making progress, here is my tiny little code, and the error message i get.

 

 

Warning: filetype() [function.filetype]: Lstat failed for 0003000_1869WEB.jpg in /hermes/bosweb/web173/public_html/PHOTO/display.php on line 6

 

<?php
// An Example about listing Images.
$dir = "uploads/";
$odir = opendir($dir);
while($file = readdir($odir)){
if(filetype($file) == "image/JPEG") {
echo '<img src=/uploads/"' . $file . '" />';
}
}
?>

anyone? Bueller? hehe. I changed the code to this, I get an image icon but no image on the page.

please any help thanks.

 

<?php
if ($handle = opendir('uploads/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<img src='" . $file . "' />\n";
}
}
closedir($handle);
}

?>

ok I have it narrowed down to this

 

<?php
$dir="uploads/";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {

echo "<img src='" . $file . "' />\n";

}
closedir($handle);
}
?>

 

I get 4 image blank squares icons. not the images

great thank you!. Also, I get a grayed out or x'ed out little image placeholder square next to the image, any more help appreciated. thanks. I have been working on this code for over an hour. LOL

 

edit: when I added this

 

echo "<img src='" . $dir . $file . "' width=\"75\" height=\"75\" />\n";

 

i get 3 blank squares and one image.

actually I am trying to make a thumbnail, then an image link to the larger image. like this but it isn't working

 

 

<?php
echo "<a href=\"http://mysite.com/\"". $dir . $file."\"><img src='" . $dir . $file . "' width=\"75\" height=\"75\" /></a>\n";
?>

good eye. it feels like dissecting fleas. The page shows two blank image links, one links to the directory above uploads, and the other links to the root directory of the site. I don't know what to do please. That is about it for now, i will be happy with that. if you are able.

I have just been doing exactly what you are doing (with the same code too). And I have finally got it to work! :)

 

<?php
// fill an array with all items from a directory
$dir = "thumbs/";
$handle = opendir($dir);
while ($file = readdir($handle)) {
 $files[] = $file;

 // This removes the full stops from the array
unset($files[0]);
unset($files[1]);

}
foreach($files as $file)
{
	echo "<img src='" . $dir . $file . "' />\n";

}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.