Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 did you want me to post it again? Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506766 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 please. Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506785 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 ok HTML <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: You talkin' to me?</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> <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> PHP <?php //connect to db require_once('dbconnection.php'); //added suggestion if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n"; echo "Displaying contents\n"; readfile($_FILES['userfile']['tmp_name']); //pull var from form $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_POST['image_filename']; $today = date("Y-m-d"); //upload image and check for image type //path not working $imageDir = "C:/projects/pratice/WWW/ch07/images/"; $imageName = $imageDir . $image_tempname; //check to see if file is valid upload file (uploaded by post) 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 "; 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> <p>Here is the picture you just uploaded to our servers:</p> <img src = "images/<?php echo $lastpicid . $ext;?>" align="left"> <strong><?php echo $image_name;?></strong> This image is a <?php echo $ext;?> image. It is <?php echo $width;?> pixels wide and <?php echo $height;?> pixels high. It was uploaded on <?php echo $today;?>. </body> </html> EDITED BY WILDTEEN88: Please use code tags ( ) when posting code. Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506787 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 TRry: <?php //connect to db require_once('dbconnection.php'); //pull var from form $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_POST['image_filename']; $today = date("Y-m-d"); //upload image and check for image type //path not working $imageDir = "C:/projects/pratice/WWW/ch07/images/"; $imageName = $imageDir . $image_tempname; //check to see if file is valid upload file (uploaded by post) if (is_uploaded_file($imageName)){ 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 "; 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> <p>Here is the picture you just uploaded to our servers:</p> <img src = "images/<?php echo $lastpicid . $ext;?>" align="left"> <strong><?php echo $image_name;?></strong> This image is a <?php echo $ext;?> image. It is <?php echo $width;?> pixels wide and <?php echo $height;?> pixels high. It was uploaded on <?php echo $today;?>. </body> </html> Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506795 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 Warning: move_uploaded_file(C:/projects/pratice/WWW/ch07/images/) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\projects\pratice\WWW\ch07\check_image.php on line 17 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpDF.tmp' to 'C:/projects/pratice/WWW/ch07/images/' in C:\projects\pratice\WWW\ch07\check_image.php on line 17 Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506798 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 did u try the above code ??? Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506799 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I guess not what above code. It looks like you just deleted a chunk we tested earlier. Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506800 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 you dont need it i modifified the image code to is_uploaded_file so it checks if $imageName which is dirname.filename right? so if it is uploaded it moves on Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506801 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 The error msg goes away but the image doesn't display Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506802 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 try turning on error_reporting <?php ini_set('error_reporting',E_ALL);?> Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506803 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I hit the motherload Undefined index: image_filename in C:\projects\pratice\WWW\ch07\check_image.php on line 9 Undefined variable: lastpicid in C:\projects\pratice\WWW\ch07\check_image.php on line 65 Undefined variable: ext in C:\projects\pratice\WWW\ch07\check_image.php on line 67 Undefined variable: width in C:\projects\pratice\WWW\ch07\check_image.php on line 68 Undefined variable: height in C:\projects\pratice\WWW\ch07\check_image.php on line 69 Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506805 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 According to my debuger the if statement if (is_uploaded_file($imageName)) is still reading false. I will jump past the code inside the if statement and move on to whats underneath it Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506816 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 try doing this and tell me what it outputs <?php print_r($lastpicid); print_r($height); print_r($width); print_r($ext); print_r($image_tempname); ?> Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506819 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 $lastpicid is not set $width not set $height not set $image_tempname not set $ext not set I know the height and width aren't being set because they don't even hit the list statement that sets them. Same with the $ext. Let me check one more then regarding the $lastpicid. I'm not sure why the image_tempname is not being set Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506827 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 $lastpicid is not being set because the query fails, in other words its empty. I think a major problem is that if statement, it fails and nothing gets set Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506830 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 $image_tempname was supposed to be $image_tempname = $_FILES['image_filename']['name']; Now its being set but the if statement still reads false so nothing in the if statement is even read Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506832 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 <?php //connect to db require_once('dbconnection.php'); //pull var from form $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_FILES['image_filename']['name']; $today = date("Y-m-d"); //make sure posts are set if(isset($_POST['image_username'])||isset($_POST['image_caption'])) { //upload image and check for image type //path not working $imageDir = "C:/projects/pratice/WWW/ch07/images/"; $imageName = $imageDir . basename($_FILES //check to see if file is valid upload file (uploaded by post) if (is_uploaded_file($_FILES{ 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 "; 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); } } ?> Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506837 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I got it fixed I need to work some bugs out but heres what I did I changed this $image_tempname = $_FILES['image_filename']['name']; and changed my if statement back to this if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $imageName)) I don't know if I should laugh or cry all this trouble because I missed type a var. Thank you so much for your help I'm really grateful Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506847 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 solve topic thanks Link to comment https://forums.phpfreaks.com/topic/99025-images/page/2/#findComment-506852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.