AmericanAlien Posted September 6, 2011 Share Posted September 6, 2011 Hello all, I am having an issue. I have read many articles and help forums, but I cannot find a specific way to help me. My issue is this. I have a php upload form for visitors to upload an image. Now, I would like to know how to get the uploaded images to show up after the upload. Someone suggested to me to call the images. However, I am not sure how to do this. Below is the script for the image upload, which works great for uploading. <?php /* This script can send an email and/or make an entry in a log file There are two variables below - one for an email address and one for a log file Set both variables to the values you want to use If you do not want either an email or log entry, comment out the respective line For example, if you do not want an email sent, put a // in front of the $emailAddress line - same for the $logFile line */ $logFile = $_SERVER['DOCUMENT_ROOT'].'/upload.log'; // full path to your log file $emailaddress = "email@gmail.com"; $home_page = "index.html"; // used for a link to return $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $fileTypeArray = array(".jpg",".gif",".txt"); // enter in all lower case, the script will handle a match with upper case $maxSize = 500000; // maximum file size that can be uploaded - in bytes $maxFileSpace = 50000000; // maximum space that can be used by files matching the $fileTypeArray array in the upload directory - in bytes putenv('TZ=EST5EDT'); // eastern time // change nothing below this line $maxDisplay = $maxSize / 1000; ?> <html><head></head><body> <div style="text-align: center; margin: 100px auto; border: 1px black solid; width:400px;"> <?php // print_r($_FILES); // can be used for debugging $file_name = $_FILES['file']['name']; $file_size = $_FILES['file']['size']; $file_tmp_name = $_FILES['file']['tmp_name']; if (!empty($file_name)) { unset($error); echo "<br>File Name: $file_name<br><br>"; echo "File Size: $file_size bytes<br><br>"; // file size test if ($file_size == 0 ) $error .= "<span style='color: red;'>Invalid file</span><br>"; if ($file_size > $maxSize ) $error .= "<span style='color: red;'>Your file exceeds $maxDisplay K.</span><br>"; // file type test if (!in_array(strtolower(strrchr($file_name,'.')),$fileTypeArray) ) $error .= "<span style='color: red;'>Your file is not a valid file type.</span><br>"; // max directory size test foreach(scandir($uploaddir) as $file_select) if (in_array(strtolower(strstr($file_select,'.')),$fileTypeArray)) $total_size = $total_size + filesize($uploaddir.$file_select); if (($total_size + $file_size) >= $maxFileSpace) $error .= "<span style='color: red;'>Total file space limits have been exceeded.</span><br>"; // scrub characters in the file name $file_name = stripslashes($file_name); $file_name = preg_replace("#[ ]#","_",$file_name); // change spaces to underscore $file_name = preg_replace('#[^()\.\-,\w]#','_',$file_name); //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore $file_name = preg_replace('#(_)+#','_',$file_name); //eliminate duplicate underscore // check for file already exists if (file_exists($uploaddir.$file_name)) $error .= "<span style='color: red;'>File already exists.</span><br>"; // if all is valid, do the upload if (empty($error)) { if (move_uploaded_file($file_tmp_name,$uploaddir.$file_name)) { chmod($uploaddir.$file_name,0644); echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; if (isset($emailAddress)) { $message = $file_name . " was uploaded by".$_SERVER['REMOTE_ADDR']."at".date('Y-m-d H:i:s'); mail($emailaddress,"You have a file upload",$message,"From: Website <>"); } if (isset($logFile)) { $logData = $file_name."||".$_SERVER['REMOTE_ADDR']."||".date('Y-m-d H:i:s')."\r\n"; @file_put_contents($logFile,$logData,FILE_APPEND|LOCK_EX); } } else { echo "<span style='color: red;'>Your file could not be uploaded.</span>"; } } echo "$error<hr>"; } ?> <p>Upload a <span style="color: blue;"> <?php foreach($fileTypeArray as $fileType) echo $fileType; ?> </span> file to our server<br> Maximum file size is <?php echo $maxDisplay; ?>K</p> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data"> File: <input type="file" name="file" style="width: 250px;"><br> <input type="submit" name="submit" value="Upload File"></form> <a href="<?php echo $home_page; ?>">Return to the Home Page</a> </div> What is the method or process to get the images to show up or to pull the images from the folder to a webpage? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/ Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 After this code echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; Add new code echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; echo "<img src='$uploaddir.$file_name' />"; http://www.tizag.com/htmlT/htmlimagelinks.php Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265829 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 Well, I have to admit, that is the closest I have gotten. The pic does show up. THANK YOU! However, I would like it to show up to a new webpage and stay there. Something like: <form method="post" action="gallery.php"> Would something like this work? Have the php shoot to that upload gallery and then have the gallery display with the new image? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265838 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 You want to upload the image and display in different page Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265843 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 Yes, that is what I am trying to achieve. I am just not succeeding at it. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265844 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 After this code. echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; Add new code echo "<span style='color: green;'>Your file was successfully uploaded!</span>";echo "<img src='$uploaddir.$file_name' />"; $config_basedir="http://www.XXX.com/"; header("Location:".$config_basedir ."display.php?imageName=".$file_name ); exit(); display.php <?php // please validate the input $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $file_name = $_GET['imageName']; echo "<img src='$uploaddir.$file_name' />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265845 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 You have been a tremendous help. I just cannot get it to work, I must be missing something, or a path or a pattern. I will keep trying. I know it is late, but hopefully I can get it to work soon. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265864 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1265902 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 My code is as follows: <?php /* This script can send an email and/or make an entry in a log file There are two variables below - one for an email address and one for a log file Set both variables to the values you want to use If you do not want either an email or log entry, comment out the respective line For example, if you do not want an email sent, put a // in front of the $emailAddress line - same for the $logFile line */ $logFile = $_SERVER['DOCUMENT_ROOT'].'/upload.log'; // full path to your log file $emailaddress = "email@gmail.com"; $home_page = "index.html"; // used for a link to return $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $fileTypeArray = array(".jpg",".gif",".txt"); // enter in all lower case, the script will handle a match with upper case $maxSize = 500000; // maximum file size that can be uploaded - in bytes $maxFileSpace = 50000000; // maximum space that can be used by files matching the $fileTypeArray array in the upload directory - in bytes putenv('TZ=EST5EDT'); // eastern time // change nothing below this line $maxDisplay = $maxSize / 1000; ?> <html><head></head><body> <div style="text-align: center; margin: 100px auto; border: 1px black solid; width:400px;"> <?php // print_r($_FILES); // can be used for debugging $file_name = $_FILES['file']['name']; $file_size = $_FILES['file']['size']; $file_tmp_name = $_FILES['file']['tmp_name']; if (!empty($file_name)) { unset($error); echo "<br>File Name: $file_name<br><br>"; echo "File Size: $file_size bytes<br><br>"; // file size test if ($file_size == 0 ) $error .= "<span style='color: red;'>Invalid file</span><br>"; if ($file_size > $maxSize ) $error .= "<span style='color: red;'>Your file exceeds $maxDisplay K.</span><br>"; // file type test if (!in_array(strtolower(strrchr($file_name,'.')),$fileTypeArray) ) $error .= "<span style='color: red;'>Your file is not a valid file type.</span><br>"; // max directory size test foreach(scandir($uploaddir) as $file_select) if (in_array(strtolower(strstr($file_select,'.')),$fileTypeArray)) $total_size = $total_size + filesize($uploaddir.$file_select); if (($total_size + $file_size) >= $maxFileSpace) $error .= "<span style='color: red;'>Total file space limits have been exceeded.</span><br>"; // scrub characters in the file name $file_name = stripslashes($file_name); $file_name = preg_replace("#[ ]#","_",$file_name); // change spaces to underscore $file_name = preg_replace('#[^()\.\-,\w]#','_',$file_name); //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore $file_name = preg_replace('#(_)+#','_',$file_name); //eliminate duplicate underscore // check for file already exists if (file_exists($uploaddir.$file_name)) $error .= "<span style='color: red;'>File already exists.</span><br>"; // if all is valid, do the upload if (empty($error)) { if (move_uploaded_file($file_tmp_name,$uploaddir.$file_name)) { chmod($uploaddir.$file_name,0644); echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; if (isset($emailAddress)) { $message = $file_name . " was uploaded by".$_SERVER['REMOTE_ADDR']."at".date('Y-m-d H:i:s'); mail($emailaddress,"You have a file upload",$message,"From: Website <>"); } if (isset($logFile)) { $logData = $file_name."||".$_SERVER['REMOTE_ADDR']."||".date('Y-m-d H:i:s')."\r\n"; @file_put_contents($logFile,$logData,FILE_APPEND|LOCK_EX); } } else { echo "<span style='color: red;'>Your file could not be uploaded.</span>"; } } echo "$error<hr>"; } ?> <p>Upload a <span style="color: blue;"> <?php foreach($fileTypeArray as $fileType) echo $fileType; ?> </span> file to our server<br> Maximum file size is <?php echo $maxDisplay; ?>K</p> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data"> File: <input type="file" name="file" style="width: 250px;"><br> <input type="submit" name="submit" value="Upload File"></form> <a href="<?php echo $home_page; ?>">Return to the Home Page</a> and the display.php is: <?php // please validate the input $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $file_name = $_GET['imageName']; echo "<img src='$uploaddir.$file_name' />"; ?> I get this error: Warning: Cannot modify header information - headers already sent by (output started at /homepages/1/d225596241/htdocs/enter.php:6) in /homepages/1/d225596241/htdocs/enter.php on line 183 Line 183 is: header("Location:".$config_basedir ."display.php?imageName=".$file_name ); exit(); The pic shows up after the upload, but it does not go to the display.php page nor does it automatically go to that page. Also, after the upload and the pic shows up the error I provided is show below. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266106 Share on other sites More sharing options...
radiations3 Posted September 6, 2011 Share Posted September 6, 2011 from where would you like to display the uploaded image blob field or from any certain directory?? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266110 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 in the main page where is line 183? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266112 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 from where would you like to display the uploaded image blob field or from any certain directory?? I want the images displayed in another webpage and for it to go directly to that page after the upload. The file it pulls the image from is uploads. As you can see from the code, it is trying to pull from that folder. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266116 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 in the main page where is line 183? As from my previous post line 183 is: header("Location:".$config_basedir ."display.php?imageName=".$file_name ); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266119 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 header("Location:".$config_basedir ."display.php?imageName=".$file_name ); exit(); where is it? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266121 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 header("Location:".$config_basedir ."display.php?imageName=".$file_name ); exit(); where is it? I am not understanding your question. Below is the code you suggested. You said to add the code (error 183) below the "successfully uploaded!" portion. After this code. echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; Add new code echo "<span style='color: green;'>Your file was successfully uploaded!</span>";echo "<img src='$uploaddir.$file_name' />"; $config_basedir="http://www.XXX.com/"; header("Location:".$config_basedir ."display.php?imageName=".$file_name ); exit(); display.php <?php // please validate the input $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $file_name = $_GET['imageName']; echo "<img src='$uploaddir.$file_name' />"; ?> If this isn't what you mean, I really do not understand what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266123 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 place this code top of codes. /* "Warning: Cannot modify header information - headers already sent by " To avoid the header error , give value zero to $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; */ $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; ob_start(); Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266126 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 place this code top of codes. /* "Warning: Cannot modify header information - headers already sent by " To avoid the header error , give value zero to $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; */ $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; ob_start(); Place this on top of which portion of the code? The main code? I will try that. Thanks for help! Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266137 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 After <? php Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266139 Share on other sites More sharing options...
radiations3 Posted September 6, 2011 Share Posted September 6, 2011 Well i didn't check your code but what i did is after storing the form data to my database i get the id of my most recent used id where all of the input data is saved including the image's path I used the following code to retrieve the image: <img src="get.php?id=<?php echo $row_Recordset1['ID']; ?>" width="270" height="270" /> // FOR BLOB FIELD <img src = "<?php echo $row_Recordset1['pic']; ?>" width="100" height="100" /> // FOR CERTAIN DIRECTORY WHOSE PATH IS SAVED IN THE DATABASE Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266140 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 After <? php I figured, I just wanted to be safe, but I still get the same error, and I still do not have any images on the display.php page. I am not sure what is going on. I have tried to get this down. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266142 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 Well i didn't check your code but what i did is after storing the form data to my database i get the id of my most recent used id where all of the input data is saved including the image's path I used the following code to retrieve the image: <img src="get.php?id=<?php echo $row_Recordset1['ID']; ?>" width="270" height="270" /> // FOR BLOB FIELD <img src = "<?php echo $row_Recordset1['pic']; ?>" width="100" height="100" /> // FOR CERTAIN DIRECTORY WHOSE PATH IS SAVED IN THE DATABASE The database option might be the only way to go. I was really hoping I could just pull the images from my upload file (after the upload) and then have them displayed in a new page via php. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266143 Share on other sites More sharing options...
radiations3 Posted September 6, 2011 Share Posted September 6, 2011 WEll i think it should be possible I give you two suggestions: 1: Use the database for the form data. 2: If you don't want to use database then you have to store image temporarily some where on your server in order to display image onto the next page by simply giving its path to the following code. You can assign the image if its not big enough to a variable as well and by using header function displaying the image (If i am not wrong) <img src = "<?php echo $row_Recordset1['pic']; ?>" width="100" height="100" /> I CAN HELP YOU WITH BLOB.... Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266150 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 YOUR FULL CODE ( tested and it working) Main Page <?php /* "Warning: Cannot modify header information - headers already sent by " To avoid the header error , give value zero to $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; */ $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; ob_start(); /*This script can send an email and/or make an entry in a log file There are two variables below - one for an email address and one for a log file Set both variables to the values you want to use If you do not want either an email or log entry, comment out the respective line For example, if you do not want an email sent, put a // in front of the $emailAddress line - same for the $logFile line */ $logFile = $_SERVER['DOCUMENT_ROOT'].'/upload.log';// full path to your log $emailaddress = "email@gmail.com"; $home_page = "index.html"; // used for a link to return $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $fileTypeArray = array(".jpg",".gif",".txt"); // enter in all lower case, the script will handle a match with upper case $maxSize = 500000; // maximum file size that can be uploaded - in bytes $maxFileSpace = 50000000; // maximum space that can be used by files matching the $fileTypeArray array in the upload directory - in bytes putenv('TZ=EST5EDT'); // eastern time// change nothing below this line $maxDisplay = $maxSize / 1000; ?> <html><head></head><body><div style="text-align: center; margin: 100px auto; border: 1px black solid; width:400px;"> <?php $file_name = $_FILES['file']['name']; $file_size = $_FILES['file']['size']; $file_tmp_name = $_FILES['file']['tmp_name']; if (!empty($file_name)) { unset($error); echo "<br>File Name: $file_name<br><br>"; echo "File Size: $file_size bytes<br><br>"; // file size test if ($file_size == 0 ) $error .= "<span style='color: red;'>Invalid file</span><br>"; if ($file_size > $maxSize ) $error .= "<span style='color: red;'>Your file exceeds $maxDisplay K.</span><br>"; // file type test if (!in_array(strtolower(strrchr($file_name,'.')),$fileTypeArray) ) $error .= "<span style='color: red;'>Your file is not a valid file type.</span><br>"; // max directory size test foreach(scandir($uploaddir) as $file_select) if (in_array(strtolower(strstr($file_select,'.')),$fileTypeArray)) $total_size = $total_size + filesize($uploaddir.$file_select); if (($total_size + $file_size) >= $maxFileSpace) $error .= "<span style='color: red;'>Total file space limits have been exceeded.</span><br>"; // scrub characters in the file name $file_name = stripslashes($file_name); $file_name = preg_replace("#[ ]#","_",$file_name); // change spaces to underscore $file_name = preg_replace('#[^()\.\-,\w]#','_',$file_name); //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore $file_name = preg_replace('#(_)+#','_',$file_name); //eliminate duplicate underscore // check for file already exists if (file_exists($uploaddir.$file_name)) $error .= "<span style='color: red;'>File already exists.</span><br>"; // if all is valid, do the upload if (empty($error)) { if (move_uploaded_file($file_tmp_name,$uploaddir.$file_name)) { chmod($uploaddir.$file_name,0644); //echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; /* 1st send the email confirmation to user 2nd redirect to display.php to show the image */ if (isset($emailAddress)) { $message = $file_name . " was uploaded by".$_SERVER['REMOTE_ADDR']."at".date('Y-m-d H:i:s'); mail($emailaddress,"You have a file upload",$message,"From: Website <>"); } if (isset($logFile)) { $logData = $file_name."||".$_SERVER['REMOTE_ADDR']."||".date('Y-m-d H:i:s')."\r\n"; @file_put_contents($logFile,$logData,FILE_APPEND|LOCK_EX); } ## redirect to display.php header("Location:display.php?imageName=".$file_name ); exit(); } else { echo "<span style='color: red;'>Your file could not be uploaded.</span>"; } } echo "$error<hr>";} ?> <p>Upload a <span style="color: blue;"> <?php foreach($fileTypeArray as $fileType) echo $fileType;?> </span> file to our server<br>Maximum file size is <?php echo $maxDisplay; ?>K</p> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data"> File: <input type="file" name="file" style="width: 250px;"><br> <input type="submit" name="submit" value="Upload File"> </form><a href="<?php echo $home_page; ?>">Return to the Home Page</a> display.php <?php // please validate the input $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $file_name = $_GET['imageName']; echo "<img src='$uploaddir/$file_name' />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266161 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 WEll i think it should be possible I give you two suggestions: 1: Use the database for the form data. 2: If you don't want to use database then you have to store image temporarily some where on your server in order to display image onto the next page by simply giving its path to the following code. You can assign the image if its not big enough to a variable as well and by using header function displaying the image (If i am not wrong) <img src = "<?php echo $row_Recordset1['pic']; ?>" width="100" height="100" /> I CAN HELP YOU WITH BLOB.... That is interesting, I didn't think about echo $row, This would need the database built, no? Or is this doing its own row built from the file on the server? That might be the way to go. I will try to see if I can do this. BLOB is definitely a weak point for me, this looks like very good practice for me. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266172 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 YOUR FULL CODE ( tested and it working) Main Page <?php /* "Warning: Cannot modify header information - headers already sent by " To avoid the header error , give value zero to $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; */ $mosConfig_locale_debug = 0; $mosConfig_locale_use_gettext = 0; ob_start(); /*This script can send an email and/or make an entry in a log file There are two variables below - one for an email address and one for a log file Set both variables to the values you want to use If you do not want either an email or log entry, comment out the respective line For example, if you do not want an email sent, put a // in front of the $emailAddress line - same for the $logFile line */ $logFile = $_SERVER['DOCUMENT_ROOT'].'/upload.log';// full path to your log $emailaddress = "email@gmail.com"; $home_page = "index.html"; // used for a link to return $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $fileTypeArray = array(".jpg",".gif",".txt"); // enter in all lower case, the script will handle a match with upper case $maxSize = 500000; // maximum file size that can be uploaded - in bytes $maxFileSpace = 50000000; // maximum space that can be used by files matching the $fileTypeArray array in the upload directory - in bytes putenv('TZ=EST5EDT'); // eastern time// change nothing below this line $maxDisplay = $maxSize / 1000; ?> <html><head></head><body><div style="text-align: center; margin: 100px auto; border: 1px black solid; width:400px;"> <?php $file_name = $_FILES['file']['name']; $file_size = $_FILES['file']['size']; $file_tmp_name = $_FILES['file']['tmp_name']; if (!empty($file_name)) { unset($error); echo "<br>File Name: $file_name<br><br>"; echo "File Size: $file_size bytes<br><br>"; // file size test if ($file_size == 0 ) $error .= "<span style='color: red;'>Invalid file</span><br>"; if ($file_size > $maxSize ) $error .= "<span style='color: red;'>Your file exceeds $maxDisplay K.</span><br>"; // file type test if (!in_array(strtolower(strrchr($file_name,'.')),$fileTypeArray) ) $error .= "<span style='color: red;'>Your file is not a valid file type.</span><br>"; // max directory size test foreach(scandir($uploaddir) as $file_select) if (in_array(strtolower(strstr($file_select,'.')),$fileTypeArray)) $total_size = $total_size + filesize($uploaddir.$file_select); if (($total_size + $file_size) >= $maxFileSpace) $error .= "<span style='color: red;'>Total file space limits have been exceeded.</span><br>"; // scrub characters in the file name $file_name = stripslashes($file_name); $file_name = preg_replace("#[ ]#","_",$file_name); // change spaces to underscore $file_name = preg_replace('#[^()\.\-,\w]#','_',$file_name); //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore $file_name = preg_replace('#(_)+#','_',$file_name); //eliminate duplicate underscore // check for file already exists if (file_exists($uploaddir.$file_name)) $error .= "<span style='color: red;'>File already exists.</span><br>"; // if all is valid, do the upload if (empty($error)) { if (move_uploaded_file($file_tmp_name,$uploaddir.$file_name)) { chmod($uploaddir.$file_name,0644); //echo "<span style='color: green;'>Your file was successfully uploaded!</span>"; /* 1st send the email confirmation to user 2nd redirect to display.php to show the image */ if (isset($emailAddress)) { $message = $file_name . " was uploaded by".$_SERVER['REMOTE_ADDR']."at".date('Y-m-d H:i:s'); mail($emailaddress,"You have a file upload",$message,"From: Website <>"); } if (isset($logFile)) { $logData = $file_name."||".$_SERVER['REMOTE_ADDR']."||".date('Y-m-d H:i:s')."\r\n"; @file_put_contents($logFile,$logData,FILE_APPEND|LOCK_EX); } ## redirect to display.php header("Location:display.php?imageName=".$file_name ); exit(); } else { echo "<span style='color: red;'>Your file could not be uploaded.</span>"; } } echo "$error<hr>";} ?> <p>Upload a <span style="color: blue;"> <?php foreach($fileTypeArray as $fileType) echo $fileType;?> </span> file to our server<br>Maximum file size is <?php echo $maxDisplay; ?>K</p> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data"> File: <input type="file" name="file" style="width: 250px;"><br> <input type="submit" name="submit" value="Upload File"> </form><a href="<?php echo $home_page; ?>">Return to the Home Page</a> display.php <?php // please validate the input $uploaddir = "uploads/"; // the directory where files are to be uploaded - include the trailing slash $file_name = $_GET['imageName']; echo "<img src='$uploaddir/$file_name' />"; ?> I tried the code again and it still errors. Are you getting a page with the image (from display.php?) because I do not and I just get the confirmation page, and when I go to the display.php, it shows me nothing but a broken image. Attached is the error (error 77 is still the same line of code.) header("Location:display.php?imageName=".$file_name ); exit(); I have used your code exactly and just used the basics. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/#findComment-1266175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.