Jump to content

Recommended Posts

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");
	}
}	

Link to comment
https://forums.phpfreaks.com/topic/139022-image-database-upload/
Share on other sites

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 =)

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.

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");
	}
}

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");
      }
   }
}
?>

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

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 

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.

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>';
}

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.

$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..

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..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.