sprint10s Posted August 31, 2009 Share Posted August 31, 2009 below i am working with two files that will allow a user to upload a picture insert the information of it to the database and add the picture from their computer to a directory on the server then return the image to the screen with the information about it. the images are getting uploaded to the right directory and the database table is getting inserted correctly but the picture is not being displayed back to the screen just a little blue ? box (image can't be displayed icon). Any suggestions or help is appreciated. thanks here is the link http://www.standridgemotorsports.com/upload_scripts/upload_image.htm upload image.htm <html> <head> <title>Upload your pic to our site!</title> </head> <body> <form name="form1" method="post" action="check_image.php" enctype="multipart/form-data"> <table border="0" cellpadding="5"> <tr> <td>Image Title or Caption<br> <em>Example: Jeremy_8_29_09</em></td> <td><input name="image_caption" type="text" id="item_caption" size="55" maxlength="255"></td> </tr> <tr> <td>Your Username</td> <td><input name="image_username" type="text" id="image_username" size="15" maxlength="255"></td> </tr> <td>Upload Image:</td> <td><input name="image_filename" type="file" id="image_filename"></td> </tr> </table> <br> <em>Acceptable image formats include: GIF, JPG/JPEG, and PNG.</em> <p align="center"><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Clear Form"> </p> </form> </body> </html> --- create_image.php <?php //connect to the database require_once ("../func/connect.php"); //make variables available $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_FILES['image_filename']['name']; $today = date("Y-m-d"); //upload image and check for image type //make sure to change your path to match your images directory $ImageDir ="../images/user_uploads/"; $ImageName = $ImageDir . $image_tempname; if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName)) { //get info about the image being uploaded list($width, $height, $type, $attr) = getimagesize($ImageName); switch ($type) { case 1: $ext = ".gif"; break; case 2: $ext = ".jpg"; break; case 3: $ext = ".png"; break; default: echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file.<br>"; echo "Please hit your browser's 'back' button and try again."; } //insert info into image table $insert = "INSERT INTO images (image_caption, image_username, image_date) VALUES ('$image_caption', '$image_username', '$today')"; $insertresults = mysql_query($insert) or die(mysql_error()); $lastpicid = mysql_insert_id(); $newfilename = $ImageDir . $lastpicid . $ext; rename($ImageName, $newfilename); } ?> <html> <head> <title>Here is your pic!</title> </head> <body> <h1>So how does it feel to be famous?</h1><br><br> <p>Here is the picture you just uploaded to our servers:</p> <img src="../images/user_uploads/<?php echo $lastpicid . $ext; ?>" align="left"> <strong><?php echo $image_name; ?></strong><br> This image is a <?php echo $ext; ?> image.<br> It is <?php echo $width; ?> pixels wide and <?php echo $height; ?> pixels high.<br> It was uploaded on <?php echo $today; ?>. </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/ Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 this is just a guess, but you probably want this to be <?php echo $lastpicid .".". $ext; ?> otherwise, the source of the image would look like "mypicjpg" (assuming that $lastpicid is the name of the file, and $ext is the file extension Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/#findComment-909865 Share on other sites More sharing options...
sprint10s Posted August 31, 2009 Author Share Posted August 31, 2009 tried that, same result, im totally lost on this one Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/#findComment-909871 Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 are you sure your img path is right. Try echoing what the img src would be and see if it is correct Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/#findComment-909872 Share on other sites More sharing options...
sprint10s Posted September 2, 2009 Author Share Posted September 2, 2009 I now know what the problem is every time it uploads the new image the image don't have the right permissions. I need some sort of script that automatically gives the uploaded file 755 permissions to be viewed. Can someone help me do this the directory is images/user_uploads thanks Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/#findComment-910671 Share on other sites More sharing options...
DavidAM Posted September 2, 2009 Share Posted September 2, 2009 Add chmod after you rename the file ... $newfilename = $ImageDir . $lastpicid . $ext; rename($ImageName, $newfilename); chmod ($newfilename, 0755); note the leading zero on the permissions, this makes it an octal literal, if you use 755 (without leading zero) it will not be the correct permissions. Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/#findComment-910685 Share on other sites More sharing options...
sprint10s Posted September 2, 2009 Author Share Posted September 2, 2009 thank you so much for the help!!! Quote Link to comment https://forums.phpfreaks.com/topic/172607-solved-image-not-being-displayed/#findComment-910690 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.