garydt Posted March 24, 2007 Author Share Posted March 24, 2007 ok, i did those changes and i got Notice: Undefined index: MM_Username in C:\Program Files\xampp\htdocs\epeople\uploadforom3.php on line 58 Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\epeople\uploadforom3.php:58) in C:\Program Files\xampp\htdocs\epeople\uploadforom3.php on line 65 <?php require_once('Connections/elvisdb.php'); ?> <?php session_start(); error_reporting(E_ALL); $editFormAction = ''; $max_file_size = 1024*1024*1024; //1MB if(isset($_POST['sent'])){ unset($submit); if (isset($_POST['sent'])) $submit = true; else die('Error: No file got sent'); $fieldname = 'file'; function resizeimage($name){ $filename = './uploads/'.$name['name']; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 100px; max width: 100px if($im_width >= $im_height) { $im_divice = $im_width / 100; }else { $im_divice = $im_height / 100; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$newimage, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } // make a note of the directory that will recieve the uploaded file // full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; $uploadsDirectory = './uploads/'; //Upload image $uploadFilename = $uploadsDirectory.$fieldname['name']; // now let's move the file to its final location and allocate the new filename to it move_uploaded_file($fieldname['tmp_name'], $uploadFilename); resizeimage($fieldname['name']); $user = $_SESSION['MM_Username']; mysql_select_db($database_elvisdb, $elvisdb); $insertSQL = sprintf("INSERT INTO images (imageName, usnm) VALUES ('$uploadFilename', '$user')"); $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()); header("Location: userpage.php"); } ?> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> <h1> Upload form </h1> <p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> </p> <p> <label for="file">File to upload:</label> <input id="file" type="file" name="file"> </p> <p> <label> <input name="sent" type="hidden" id="sent" value="1" /> </label> </p> <p> <label for="submit">Press to...</label> <input id="submit" type="submit" name="submit" value="Upload me!"> </p> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 that's because of $user = $_SESSION['MM_Username']; $_SESSION['MM_Username'] is not defined. And the header can't get changed because of that warning. Please read my links to learn php. Quote Link to comment Share on other sites More sharing options...
garydt Posted March 24, 2007 Author Share Posted March 24, 2007 sorry, i didn't have a user logged in. I've got no errors now but no image is uploaded and it inserts into the database an url - ./uploads/f What does this mean? Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 pardon... i didn't change $fieldname: <?php require_once('Connections/elvisdb.php'); ?> <?php session_start(); error_reporting(E_ALL); $editFormAction = ''; $max_file_size = 1024*1024*1024; //1MB if(isset($_POST['sent'])){ unset($submit); if (isset($_POST['sent'])) $submit = true; else die('Error: No file got sent'); $fieldname = 'file'; function resizeimage($name){ $filename = './uploads/'.$name['name']; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 100px; max width: 100px if($im_width >= $im_height) { $im_divice = $im_width / 100; }else { $im_divice = $im_height / 100; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$newimage, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } // make a note of the directory that will recieve the uploaded file // full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; $uploadsDirectory = './uploads/'; //Upload image $uploadFilename = $uploadsDirectory.$fieldname['name']; // now let's move the file to its final location and allocate the new filename to it move_uploaded_file($fieldname['tmp_name'], $uploadFilename); resizeimage($fieldname['name']); $user = $_SESSION['MM_Username']; mysql_select_db($database_elvisdb, $elvisdb); $insertSQL = sprintf("INSERT INTO images (imageName, usnm) VALUES ('$uploadFilename', '$user')"); $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()); header("Location: userpage.php"); } ?> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> <h1> Upload form </h1> <p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> </p> <p> <label for="file">File to upload:</label> <input id="file" type="file" name="file"> </p> <p> <label> <input name="sent" type="hidden" id="sent" value="1" /> </label> </p> <p> <label for="submit">Press to...</label> <input id="submit" type="submit" name="submit" value="Upload me!"> </p> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
garydt Posted March 24, 2007 Author Share Posted March 24, 2007 sorry, i couldn't see what you have changed. Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 man... why isn't it changing? I just made $fieldname = 'file'; to $fieldname = $_FILES['file']; Quote Link to comment Share on other sites More sharing options...
garydt Posted March 24, 2007 Author Share Posted March 24, 2007 we have partial success! it uploads into the directory and puts the right url into the database but it isn't resizing the image. Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 Ah! I see! just replace $filename = './uploads/'.$name['name']; into $filename = './uploads/'.$name; (after resizeimage($name){) Because we already call the function with the filename. So... what's $newimage? It's undefined. I didn't put it into the code. Quote Link to comment Share on other sites More sharing options...
garydt Posted March 25, 2007 Author Share Posted March 25, 2007 I changed that and it still isn't resizing. Have I got this line right- if(imagejpeg($thumb, "thumbnails/".$name, 80)) { is thumbnails a directory? Quote Link to comment Share on other sites More sharing options...
garydt Posted March 25, 2007 Author Share Posted March 25, 2007 Ah-ha! Found the resized images in the thumbnails folder! Thank you very much for all your help and patience. Quote Link to comment Share on other sites More sharing options...
garydt Posted March 25, 2007 Author Share Posted March 25, 2007 How do i store the url to the new resized image? I tried $smallimage = './thumbnails/'.$name; but of course $name doesn't exist is it meant to overwrite the orignal image? Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 25, 2007 Share Posted March 25, 2007 instead of $name use $_FILES['file']['name'] or your $fieldname['name'] and now... get up to learn php Quote Link to comment 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.