jesj Posted June 13, 2008 Share Posted June 13, 2008 Hello I have a problem with displaying the images from a directory. I get a Forbidden 403 message and I'm not able to view the images from a browser. Here is the php code. <? //print_r($_POST); if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $newimage = "images/" . $imagename; //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } ?> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>"> <p><input type="file" name="image_file" size="20"></p> <p><input type="submit" value="Upload Image" name="action"></p> </form> <? if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } include("list_images.php"); ?> And the list_images.php code is <? $handle = @opendir("images"); if(!empty($handle)) { while(false !== ($file = readdir($handle))) { if(is_file("images/" . $file)) echo '<img src="images/' . $file . '"><br><br>'; } } closedir($handle); ?> Link to comment https://forums.phpfreaks.com/topic/110040-solved-image-uploading/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.