johntp Posted July 11, 2007 Share Posted July 11, 2007 Hey guys i have a script that will upload photos and resize to 100x100, well it uploads the pic and makes a thumbnail fine, but i get errors instead of it going back to the page to show the picture i get this error. Warning: copy() [function.copy]: Unable to access DSC03045.JPG in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 26 Warning: copy(DSC03045.JPG) [function.copy]: failed to open stream: No such file or directory in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 26 Warning: getimagesize() [function.getimagesize]: Unable to access _backup.jpg in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 27 Warning: getimagesize(_backup.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 27 Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php:26) in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 127 and here is the code. <? session_start(); require_once("include/config.php"); $new_width=100; //Image width Change if needed $new_height=100; $userId=$_SESSION['user_id']; function create_thumb2($old_imgname,$new_imgname) { $imginfo=getimagesize($old_imgname); $img_width=$imginfo[0]; $img_height=$imginfo[1]; $koeff=$img_width/$img_height; if ($img_width>$img_height) { $need_height=100; $need_width=$koeff*100; } else { $need_width=100; $need_height=$need_width/$koeff; } createthumb2($old_imgname,$need_width,$need_height,$new_imgname); } function createthumb2($IMAGE_SOURCE,$THUMB_X,$THUMB_Y,$OUTPUT_FILE){ $BACKUP_FILE = $OUTPUT_FILE . "_backup.jpg"; copy($IMAGE_SOURCE,$BACKUP_FILE); //line 26 $IMAGE_PROPERTIES = GetImageSize($BACKUP_FILE); //line 27 if (!$IMAGE_PROPERTIES[2] == 2) { return(0); } else { $SRC_IMAGE = ImageCreateFromJPEG($BACKUP_FILE); $SRC_X = ImageSX($SRC_IMAGE); $SRC_Y = ImageSY($SRC_IMAGE); if (($THUMB_Y == "0") && ($THUMB_X == "0")) { return(0); } elseif ($THUMB_Y == "0") { $SCALEX = $THUMB_X/($SRC_X-1); $THUMB_Y = $SRC_Y*$SCALEX; } elseif ($THUMB_X == "0") { $SCALEY = $THUMB_Y/($SRC_Y-1); $THUMB_X = $SRC_X*$SCALEY; } $THUMB_X = (int)($THUMB_X); $THUMB_Y = (int)($THUMB_Y); $DEST_IMAGE = imagecreatetruecolor($THUMB_X, $THUMB_Y); unlink($BACKUP_FILE); if (!imagecopyresampled($DEST_IMAGE, $SRC_IMAGE, 0, 0, 0, 0, $THUMB_X, $THUMB_Y, $SRC_X, $SRC_Y)) { imagedestroy($SRC_IMAGE); imagedestroy($DEST_IMAGE); return(0); } else { imagedestroy($SRC_IMAGE); if (ImageJPEG($DEST_IMAGE,$OUTPUT_FILE)) { imagedestroy($DEST_IMAGE); return(1); } imagedestroy($DEST_IMAGE); } return(0); } } # end createthumb function thumb_jpeg($image_name) { createthumb2($image_name,100,100,$destination_path); return true; global $source_path; global $destination_path; global $new_width; global $new_height; $destimg=imagecreatetruecolor($new_width,$new_height) or die("Problem In Creating image"); $srcimg=ImageCreateFromJPEG($source_path.$image_name) or die("Problem In opening Source Image"); $imageheight= ImageSX($srcimg); ImageCopyResampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing"); ImageJPEG($destimg,$destination_path.$image_name) or die("Problem In saving"); return true; } $source_path="Uploadimages/"; $destination_path="thumnailimages/"; $n_width=100; // Fix the width of the thumb nail images $n_height=100; while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; } else { header("location:step1.php?error=im"); } $ext = strtolower(end(explode('.', $filename))); if ($ext == 'jpg' || $ext == 'jpeg') { $add="Uploadimages/$filename"; $thumbnailpath="thumnailimages/$filename"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); $vaildupload=thumb_jpeg($filename); } } if($vaildupload=="1") { $add1="Uploadimages/$filename"; $thumbnailpath1="thumnailimages/$filename"; $query="insert into myspaceuserpicture (UserID,UseImagepath,Userthubnailpath,rankpictureflag ,imagetype,displayfalg) values ('$userId','$add1','$thumbnailpath1','0','0','1')"; createthumb2($add1,100,100,$thumbnailpath1); mysql_query($query) or handle_mysql_error($query,mysql_errno(),mysql_error); $id = mysql_insert_id($cn); $uploaddone="sucess"; } if($uploaddone=="sucess") { header("location:updatemyphoto.php"); } else { header("location:step1.php?error=ix"); } ?> Quote Link to comment Share on other sites More sharing options...
johntp Posted July 12, 2007 Author Share Posted July 12, 2007 OK. Maybe noone understands my question, so ill try to describe a little better. This script I have to upload a photo and resize it as a thumbnail to another location works, but I'm getting these errors and don't really understand what needs to be done to fix them. I was hoping somone would have an idea of what's going on. Warning: copy() [function.copy]: Unable to access DSC03045.JPG in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 26 Warning: copy(DSC03045.JPG) [function.copy]: failed to open stream: No such file or directory in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 26 Warning: getimagesize() [function.getimagesize]: Unable to access _backup.jpg in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 27 Warning: getimagesize(_backup.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 27 Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php:26) in /mounted-storage/home23b/sub003/sc21754-QIFR/www/mainscript/editphotoaction.php on line 127 and here is my code <? session_start(); require_once("include/config.php"); $new_width=100; //Image width Change if needed $new_height=100; $userId=$_SESSION['user_id']; function create_thumb2($old_imgname,$new_imgname) { $imginfo=getimagesize($old_imgname); $img_width=$imginfo[0]; $img_height=$imginfo[1]; $koeff=$img_width/$img_height; if ($img_width>$img_height) { $need_height=100; $need_width=$koeff*100; } else { $need_width=100; $need_height=$need_width/$koeff; } createthumb2($old_imgname,$need_width,$need_height,$new_imgname); } function createthumb2($IMAGE_SOURCE,$THUMB_X,$THUMB_Y,$OUTPUT_FILE){ $BACKUP_FILE = $OUTPUT_FILE . "_backup.jpg"; copy($IMAGE_SOURCE,$BACKUP_FILE); //line 26 $IMAGE_PROPERTIES = GetImageSize($BACKUP_FILE); //line 27 if (!$IMAGE_PROPERTIES[2] == 2) { return(0); } else { $SRC_IMAGE = ImageCreateFromJPEG($BACKUP_FILE); $SRC_X = ImageSX($SRC_IMAGE); $SRC_Y = ImageSY($SRC_IMAGE); if (($THUMB_Y == "0") && ($THUMB_X == "0")) { return(0); } elseif ($THUMB_Y == "0") { $SCALEX = $THUMB_X/($SRC_X-1); $THUMB_Y = $SRC_Y*$SCALEX; } elseif ($THUMB_X == "0") { $SCALEY = $THUMB_Y/($SRC_Y-1); $THUMB_X = $SRC_X*$SCALEY; } $THUMB_X = (int)($THUMB_X); $THUMB_Y = (int)($THUMB_Y); $DEST_IMAGE = imagecreatetruecolor($THUMB_X, $THUMB_Y); unlink($BACKUP_FILE); if (!imagecopyresampled($DEST_IMAGE, $SRC_IMAGE, 0, 0, 0, 0, $THUMB_X, $THUMB_Y, $SRC_X, $SRC_Y)) { imagedestroy($SRC_IMAGE); imagedestroy($DEST_IMAGE); return(0); } else { imagedestroy($SRC_IMAGE); if (ImageJPEG($DEST_IMAGE,$OUTPUT_FILE)) { imagedestroy($DEST_IMAGE); return(1); } imagedestroy($DEST_IMAGE); } return(0); } } # end createthumb function thumb_jpeg($image_name) { createthumb2($image_name,100,100,$destination_path); return true; global $source_path; global $destination_path; global $new_width; global $new_height; $destimg=imagecreatetruecolor($new_width,$new_height) or die("Problem In Creating image"); $srcimg=ImageCreateFromJPEG($source_path.$image_name) or die("Problem In opening Source Image"); $imageheight= ImageSX($srcimg); ImageCopyResampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing"); ImageJPEG($destimg,$destination_path.$image_name) or die("Problem In saving"); return true; } $source_path="Uploadimages/"; $destination_path="thumnailimages/"; $n_width=100; // Fix the width of the thumb nail images $n_height=100; while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; } else { header("location:step1.php?error=im"); } $ext = strtolower(end(explode('.', $filename))); if ($ext == 'jpg' || $ext == 'jpeg') { $add="Uploadimages/$filename"; $thumbnailpath="thumnailimages/$filename"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); $vaildupload=thumb_jpeg($filename); } } if($vaildupload=="1") { $add1="Uploadimages/$filename"; $thumbnailpath1="thumnailimages/$filename"; $query="insert into myspaceuserpicture (UserID,UseImagepath,Userthubnailpath,rankpictureflag ,imagetype,displayfalg) values ('$userId','$add1','$thumbnailpath1','0','0','1')"; createthumb2($add1,100,100,$thumbnailpath1); mysql_query($query) or handle_mysql_error($query,mysql_errno(),mysql_error); $id = mysql_insert_id($cn); $uploaddone="sucess"; } if($uploaddone=="sucess") { header("location:updatemyphoto.php"); } else { header("location:step1.php?error=ix"); } ?> Now line 26 and 27 are as follows copy($IMAGE_SOURCE,$BACKUP_FILE); //line 26 $IMAGE_PROPERTIES = GetImageSize($BACKUP_FILE); //line 27 Quote Link to comment Share on other sites More sharing options...
AdRock Posted July 12, 2007 Share Posted July 12, 2007 I don't know too much about image manipulation but this works for me. I have a form where i select which gallery i want to associate with the image and I store the image name in a database (all images go in the same folders) I have a folder called full where the original image goes and I have 2 other folders (1 for thumbnails, the other for larger images) You can use my example if you want....it works for me <?php $idir = "../images/gallery/full/"; // Path To Images Directory $tdir = "../images/gallery/thumbs/"; // Path To Thumbnails Directory $twidth = "100"; // Maximum Width For Thumbnail Images $theight = "75"; // Maximum Height For Thumbnail Images $ldir = "../images/gallery/large/"; // Path To Large Directory $lwidth = "400"; // Maximum Width For Large Images $lheight = "300"; // Maximum Height For Large Images $pic=($_FILES['imagefile']['name']); $gallery = $_POST['gallery']; if (!isset($_POST['gallery'])) { ?> <fieldset> <legend><b>Image Gallery Upload</b></legend> <form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="POST"> <p style="margin-left:10px;">Gallery to upload to:<br> <select name="gallery" size="1"> <option value="jack">Jack</option> <option value="honeylands">Honeylands</option> <option value="events">Events</option> <option value="art">Art Auction</option> </select> <p style="margin-left:10px;">Image to upload:<br> <input type="file" name="imagefile" style="width:450px"><br> <P><input type="submit" name="submit" value="Upload Image" class="submit-button" style="margin-left:10px;"></p> </form> </fieldset></p> <?} else { // Uploading/Resizing Script $url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image //insert the image names into the database include_once "../includes/connection.php"; $query = "INSERT INTO image VALUES ('','$pic','$pic','$gallery')"; mysql_query($query); mysql_close(); $simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$tdir" . $url); // Saving The Image imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image print 'Image thumbnail created successfully.'; // Resize successful } else { print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed } $simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Large From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $lwidth / $currheight; // Length Ratio For Width $newheight = $lheight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $lwidth / $currwidth; // Length Ratio For Height $newwidth = $lwidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Large imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$ldir" . $url); // Saving The Image imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image print 'Image Large created successfully.'; // Resize successful } else { print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed } } ?> Quote Link to comment Share on other sites More sharing options...
johntp Posted July 12, 2007 Author Share Posted July 12, 2007 I would really like to use this one since i've allready put the time in to get it to do what i want it too. Just need these darn errors gone. I think that part of the problem could be function createthumb2($IMAGE_SOURCE,$THUMB_X,$THUMB_Y,$OUTPUT_FILE){ $BACKUP_FILE = $OUTPUT_FILE . "_backup.jpg"; copy($IMAGE_SOURCE,$BACKUP_FILE); //line 26 $IMAGE_PROPERTIES = GetImageSize($BACKUP_FILE); //line 27 if (!$IMAGE_PROPERTIES[2] == 2) { return(0); } else { $SRC_IMAGE = ImageCreateFromJPEG($BACKUP_FILE); $SRC_X = ImageSX($SRC_IMAGE); $SRC_Y = ImageSY($SRC_IMAGE); if (($THUMB_Y == "0") && ($THUMB_X == "0")) { $IMAGE_SOURCE cause the file should either be in /Uploadimages or /thumnailimages and it's looking for it just in / I've tried testing it but i still get nothing :/ 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.