Lautarox Posted December 31, 2008 Share Posted December 31, 2008 I made this function to upload a image and it's thumbnail to a database and I'm getting an error while moving the image from the tmp folder, I have this code in a file called class.php and in the same dir, there's a folder called images. What could be happening? Thanks in advance Warning: move_uploaded_file(images/old270.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/a4631774/public_html/class.php on line 1723 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpW4DjpO' to 'images/old270.jpg' in /home/a4631774/public_html/class.php on line 1723 function photoProcess($tmppath, $imgtype, $imgsize, $imgname) { $thumb_height = 1; $thumb_width = 1; if($imgtype == "image/jpeg" && $imgsize > 0 && $imgsize < 3145728) { $rand = rand(1, 400); $oldimgpath = "images/"."old".$rand.".jpg"; $newimgthumbpath = "images/"."tumb".$rand.".jpg"; move_uploaded_file($tmppath, $oldimgpath) $size = getimagesize($pr, $oldimgpath); if($size[0] > $new_height && $size[1] > $new_width && $size[0]/$size[1] > 1) { $destimg = ImageCreateTrueColor($new_width,$new_height); $destimgthumb = ImageCreateTrueColor($thumb_width,$thumb_height); $srcimg = ImageCreateFromJPEG($oldimgpath); imagecopyresampled($destimgthumb,$srcimg,0,0,0,0,$thumb_width,$thumb_height,ImageSX($srcimg),ImageSY($srcimg)); imagejpg($destimgthumb,$newimgthumbpath,100); $fp = fopen($oldimgpath, 'r'); $content = fread($fp, filesize($destimg)); $content = addslashes($content); fclose($fp); $fp = fopen($destimgthumb, 'r'); $content2 = fread($fp, filesize($destimgthumb)); $content2 = addslashes($content2); fclose($fp); $array[0] = $content; $array[1] = $content2; return $array; imagedestroy($destimgthumb); unlink($oldimgpath); unlink($newimgthumbpath); } } else { die("Error"); } } Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/ Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 Change the path from just "images" to: /home/a4631774/public_html/images/old270.jpg Full paths are generally better than relative. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727118 Share on other sites More sharing options...
Maq Posted December 31, 2008 Share Posted December 31, 2008 Full paths are generally better than relative. Until you start moving pages from server to server... Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727152 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2008 Share Posted December 31, 2008 Use $_SERVER['DOCUMENT_ROOT'] to form an absolute file system path at runtime. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727159 Share on other sites More sharing options...
Maq Posted December 31, 2008 Share Posted December 31, 2008 Use $_SERVER['DOCUMENT_ROOT'] to form an absolute file system path at runtime. ^--- Yep. That way your relative paths will be portable on any server. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727161 Share on other sites More sharing options...
Lautarox Posted December 31, 2008 Author Share Posted December 31, 2008 Do you mean something like this? $_SERVER['DOCUMENT_ROOT']."images/"."old".$rand.".jpg Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727185 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2008 Share Posted December 31, 2008 Yes, except that $_SERVER['DOCUMENT_ROOT'] does not include a trailing slash /, so you will need to add one in your string. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727191 Share on other sites More sharing options...
Lautarox Posted December 31, 2008 Author Share Posted December 31, 2008 I'm getting this now.. Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/usr/local/apache/htdocs/images/old68.jpg) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/a4631774/public_html/class.php on line 1723 Btw, happy new year =) Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727271 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2008 Share Posted December 31, 2008 From the error message - $_SERVER['DOCUMENT_ROOT'] is /usr/local/apache/htdocs, while your actual document root where your script is at is /home/a4631774/public_html. Either your server is rewriting URLs but is not updating the document root setting or there is some other problem with your server or how your script is being invoked. Do you really need someone to read that error message for you to tell you that $_SERVER['DOCUMENT_ROOT'] is not set correctly on your server and you will either need to fix it or simply set a variable or defined constant to the correct value and use that variable or defined constant in place of $_SERVER['DOCUMENT_ROOT'] in your script. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727282 Share on other sites More sharing options...
Lautarox Posted January 1, 2009 Author Share Posted January 1, 2009 Well.. the problem was a bad located folder ¬¬, I fixed that, now I'm getting problems reading, creating the thumbnail and uploading both into the database.. Here's my actual code class bikecheck extends mysql{ function photoProcess($tmppath, $imgtype, $imgsize, $imgname) { $thumb_height = 150; $thumb_width = 233; if($imgtype == "image/jpeg" && $imgsize > 0 && $imgsize < 3145728) { $rand = rand(1, 400); $oldimgpath = "images/"."old".$rand.".jpg"; $newimgthumbpath = "images/"."thumb".$rand.".jpg"; if(!move_uploaded_file($tmppath, $oldimgpath)) { die("Errror moviendo file"); } if(!function_exists(imagecopyresampled) || !function_exists(ImageCreateTrueColor) || !function_exists(imagejpeg)) { die("Faltan funciones"); } $size = getimagesize($oldimgpath); if($size[0] > $thumb_width && $size[1] > $thumb_height && $size[1]/$size[0] > 1) { $destimgthumb = ImageCreateTrueColor($thumb_width,$thumb_height); $srcimg = ImageCreateFromJPEG($oldimgpath); imagecopyresampled($destimgthumb,$srcimg,0,0,0,0,$thumb_width,$thumb_height,ImageSX($srcimg),ImageSY($srcimg)); imagejpeg($destimgthumb,$newimgthumbpath,100); if($fp = fopen($oldimgpath, 'rb')) { $content = fread($fp, filesize($oldimgpath)); $content = addslashes($content); fclose($fp); print($content); } else { die("Error Abriendo Imagen en ".$oldimgpath.""); } if($fp = fopen($newimgthumbpath, 'rb')) { $content2 = fread($fp, filesize($newimgthumbpath)); $content2 = addslashes($content2); fclose($fp); } else { die("Error Abriendo Imagen en ".$newimgthumbpath.""); } $array[0] = $content; $array[1] = $content2; return $array; imagedestroy($destimgthumb); } } else { die("Fatal nigga"); } } Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727503 Share on other sites More sharing options...
darkfreaks Posted January 1, 2009 Share Posted January 1, 2009 Missed a Close bracket but fixed: <?php class bikecheck extends mysql{ function photoProcess($tmppath, $imgtype, $imgsize, $imgname) { $thumb_height = 150; $thumb_width = 233; if($imgtype == "image/jpeg" && $imgsize > 0 && $imgsize < 3145728) { $rand = rand(1, 400); $oldimgpath = "images/"."old".$rand.".jpg"; $newimgthumbpath = "images/"."thumb".$rand.".jpg"; if(!move_uploaded_file($tmppath, $oldimgpath)) { die("Errror moviendo file"); } if(!function_exists(imagecopyresampled) || !function_exists(ImageCreateTrueColor) || !function_exists(imagejpeg)) { die("Faltan funciones"); } $size = getimagesize($oldimgpath); if($size[0] > $thumb_width && $size[1] > $thumb_height && $size[1]/$size[0] > 1) { $destimgthumb = ImageCreateTrueColor($thumb_width,$thumb_height); $srcimg = ImageCreateFromJPEG($oldimgpath); imagecopyresampled($destimgthumb,$srcimg,0,0,0,0,$thumb_width,$thumb_height,ImageSX($srcimg),ImageSY($srcimg)); imagejpeg($destimgthumb,$newimgthumbpath,100); if($fp = fopen($oldimgpath, 'rb')) { $content = fread($fp, filesize($oldimgpath)); $content = addslashes($content); fclose($fp); print($content); } else { die("Error Abriendo Imagen en ".$oldimgpath.""); } if($fp = fopen($newimgthumbpath, 'rb')) { $content2 = fread($fp, filesize($newimgthumbpath)); $content2 = addslashes($content2); fclose($fp); } else { die("Error Abriendo Imagen en ".$newimgthumbpath.""); } $array[0] = $content; $array[1] = $content2; return $array; imagedestroy($destimgthumb); } } else { die("Fatal nigga"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727566 Share on other sites More sharing options...
Lautarox Posted January 1, 2009 Author Share Posted January 1, 2009 I'm sorry I missed the class part, I have it closed, I copied badly, the code is not working, that's the problem Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727697 Share on other sites More sharing options...
darkfreaks Posted January 1, 2009 Share Posted January 1, 2009 turn error_reporting(E_ALL); on Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727707 Share on other sites More sharing options...
Lautarox Posted January 2, 2009 Author Share Posted January 2, 2009 Why does it says this? Notice: Use of undefined constant imagecopyresampled - assumed 'imagecopyresampled' in /home/a4631774/public_html/class.php on line 1727 Free Web Hosting PHP Error Message Notice: Use of undefined constant ImageCreateTrueColor - assumed 'ImageCreateTrueColor' in /home/a4631774/public_html/class.php on line 1727 Free Web Hosting PHP Error Message Notice: Use of undefined constant imagejpeg - assumed 'imagejpeg' in /home/a4631774/public_html/class.php on line 1727 Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727740 Share on other sites More sharing options...
DarkerAngel Posted January 2, 2009 Share Posted January 2, 2009 check that you have GD installed phpinfo(); Also GD functions are all lowercase ImageCreateTrueColor -> imagecreatetruecolor (not really sure if it makes a difference.) Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727742 Share on other sites More sharing options...
Lautarox Posted January 2, 2009 Author Share Posted January 2, 2009 I've changed the names, and gd seems to be there.. What could be happening? gd GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.2.1 GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XPM Support enabled XBM Support enabled Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727761 Share on other sites More sharing options...
DarkerAngel Posted January 2, 2009 Share Posted January 2, 2009 sorry I just noticed this: if(!function_exists(imagecopyresampled) || !function_exists(ImageCreateTrueColor) || !function_exists(imagejpeg)) { die("Faltan funciones"); } if(!function_exists('imagecopyresampled') || !function_exists('ImageCreateTrueColor') || !function_exists('imagejpeg')) { } I would say try that or just get rid of that whole if condition, if its really necessary have a 'or die("Faltan funciones");' after those particular functions. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727764 Share on other sites More sharing options...
Lautarox Posted January 2, 2009 Author Share Posted January 2, 2009 Well.. now I'm getting this Notice: Undefined variable: foto in /home/a4631774/public_html/class.php on line 1765 Notice: Undefined variable: thumbnail in /home/a4631774/public_html/class.php on line 1766 function addBikeCheck() { $photoarr = $this->photoProcess($_FILES['foto']['tmp_name'], $_FILES['foto']['type'], $_FILES['foto']['size'], $_FILES['foto']['name']); $photoarr[0] = $foto; -> first error $photorr[1] = $thumbnail; -> second error print($foto); print("mitad2 \n"); print($thumbnail); $bars = $_POST['bars']; $stem = $_POST['stem']; $grips = $_POST['grips']; $frame = $_POST['frame']; $cranks = $_POST['cranks']; $pedals = $_POST['pedals']; $seatpost = $_POST['seatpost']; $seat = $_POST['seat']; $fronthub = $_POST['fronthub']; $frontrim = $_POST['frontrim']; $fronttire = $_POST['fronttire']; $rearhub = $_POST['rearhub']; $rearrim = $_POST['rearrim']; $reartire = $_POST['reartire']; $fork = $_POST['fork']; $sprocket = $_POST['sprocket']; $rider = $_POST['rider']; $query = "INSERT INTO bikecheck (bars, stem, grips, frame, cranks, pedals, seatpost, seat, fronthub, frontrim, fronttire, rearhub, rearrim, reartire, fork, sprocket, rider, foto, thumbnail) VALUES ('$bars', '$stem', '$grips', '$frame', '$cranks', '$pedals', '$seatpost', '$seat', '$fronthub', '$frontrim', '$fronttire', '$rearhub', '$rearrim', '$reartire', '$fork', '$sprocket', '$rider', '$foto', '$thumbnail')"; parent::query($query); echo 'Bike Check Agregado Correctamente, <a href="?go=9&d=1">Volver</a>'; } Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727769 Share on other sites More sharing options...
premiso Posted January 2, 2009 Share Posted January 2, 2009 The undefined variable is from $photoarr[0] = $foto; $photorr[1] = $thumbnail; You do not define $foto or $thumbnail anywhere. If you had this: function addBikeCheck() { $foto = ""; $thumbnail = ""; $photoarr = $this->photoProcess($_FILES['foto']['tmp_name'], $_FILES['foto']['type'], $_FILES['foto']['size'], $_FILES['foto']['name']); $photoarr[0] = $foto; $photorr[1] = $thumbnail; Would solve that issue. Not sure where $foto and $thumbnail are suppose to be set, but yea. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727776 Share on other sites More sharing options...
Lautarox Posted January 2, 2009 Author Share Posted January 2, 2009 $foto and $thumbnail are values from the array returned from the function I pasted before, I'm still having problems creating the thumbnail and If I print the $content, that it's supposed to have some binary code, it doesn't have anything.. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-727989 Share on other sites More sharing options...
Lautarox Posted January 2, 2009 Author Share Posted January 2, 2009 I discovered what the problem was, "if($size[1] > $thumb_width && $size[0] > $thumb_height && $size[0]/$size[1] > 1) {" I changed the positions of the $size's and now the thumbnail is created and the content is copied into the array, but is not passed in the return to the other function.. Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-728113 Share on other sites More sharing options...
Lautarox Posted January 2, 2009 Author Share Posted January 2, 2009 Please don't loose the thread, I the function is not returning the array that has the values for the pictures-- Quote Link to comment https://forums.phpfreaks.com/topic/139022-image-database-upload/#findComment-728467 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.