Jump to content

Domain Transfer Causing File Upload Problem


Mindsparks

Recommended Posts

Here's the backstory: I am helping someone transfer their website to a new hosting company. I recently uploaded all of the files from one host to another, which required me to also import the database.

 

The website itself is running perfectly fine, except for one minor problem: the ability to upload files doesn't work anymore.

 

The error I'm getting on the site itself is "Error Uploading Photo: Problem in Resizing". I didn't write the code myself and I'm not the best at debugging or writing PHP, I'm more of an HTML/CSS coder.

 

The errors are coming from these lines:

		ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or $this->errmsg="Problem in resizing";
if (isset($_FILES['photo_upload']) && ($_FILES['photo_upload']['size'] > 0)){
.
.
.
	if ($pic->isError() == false){
		$success = 1;
	}
	else{
		$msg .= "Error uploading photo: " .$pic->getErrorMessage() . "<br/>";
		$_REQUEST['photo_url'] = ""; //clear since it failed
	}
}

I'm trying to figure out how I should go about debugging this. I did a var_dump() of a few of the variables ($destimg, $srcimg): resource(7) of type (Unknown) bool(false)

 

A colleague that I work with said to try resetting the permissions in the FTP for the folders to allow "Public Write" and that should fix it, but no success with that fix.

 

As a side note, don't know if it's relevant, the "information_schema" database never imported via phpMyAdmin.

 

Link to comment
Share on other sites

Here's the rest of the statement(s) for a photo upload:

if (isset($_FILES['photo_upload']) && ($_FILES['photo_upload']['size'] > 0)){
	// try uploading photo
	if (isset($_REQUEST['photo_upload_imgname']) && $_REQUEST['photo_upload_imgname'] != ""){
		// we already have it saved, so lets overwrite it
		$pic = new Picture($ABS_PATH, $_FILES['photo_upload'], $MAX_FILE_SIZE, $_REQUEST['photo_upload_imgname']);
		$_REQUEST['photo_url'] = $_REQUEST['photo_upload_imgname'];
	}
	else{
		// create new file
		$pic = new Picture($ABS_PATH, $_FILES['photo_upload'], $MAX_FILE_SIZE);
		$_REQUEST['photo_url'] = $pic->generateRandFileName(13,"jpg");
	}
	
	if (isset($PHOTO_WIDTH)){
		$pic->resizeToWidth($PHOTO_WIDTH);
	}
	if (isset($PHOTO_HEIGHT)){
		$pic->resizeToHeight($PHOTO_HEIGHT);
	}
	$pic->save();
	
	$success = 0;
	if ($pic->isError() == false){
		$success = 1;
	}
	else{
		$msg .= "Error uploading photo: " .$pic->getErrorMessage() . "<br/>";
		$_REQUEST['photo_url'] = ""; //clear since it failed
	}
}

Link to comment
Share on other sites

Here's the entire picture class so far:

<?php

/*
 * upload and resize an image
 */
class Picture {
	var $abs_path;
	var $file_array;
	var $filename;
	
	var $save_dir;                    //where file will be saved
	var $errmsg="";            //string to be output if neccesary
	var $width;                        //height of final image
	var $height;                      //width of final image
	
	function Picture($abs_path, $file_array, $max_bytes, $filename=""){
		$this->abs_path = $abs_path;
		$this->filename = $filename;
		$this->file_array = $file_array;
		
		if ($file_array['size'] > $max_bytes){
			$this->errmsg = "File has exceeded the maximum file size permitted";
		}
	}

	// generate a random string of numChar characters.
	// return it to the user
	function generateRandFileName($numChars, $fileExt){
		$chars = array();
		for($i='a'; $i < 'z'; $i++){
			array_push($chars, $i);
		}
		for($i='A'; $i < 'Z'; $i++){
			array_push($chars, $i);
		}
		for($i=0; $i < 10; $i++){
			array_push($chars, $i);
		}
		
		// select N chars for name
		do{
			$this->filename = "";
			for($i=1; $i <= $numChars; $i++){
				$this->filename .= $chars[rand(0,count($chars)-1)];
			}
			$this->filename .= "." . $fileExt;
		}while (file_exists($this->abs_path.$this->filename));
		
		return $this->filename;
	}
		
	function save(){
		if ($this->errmsg != "")
			return false;

		if (isset($this->file_array['name']) && $this->filename != ""){
			$full_image_location = $this->abs_path.$this->filename;
			if (move_uploaded_file($this->file_array['tmp_name'], $full_image_location) == false){
				$this->errmsg = "File is not valid or could not be moved from temporary location to " . $full_image_location;
			}
		}
	}
		
	function resizeToHeight($height){
		$this->resize(0, $height);
	}
	
	function resizeToWidth($width){
		$this->resize($width, 0);
	}
	
	function resize($width=0, $height=0){
		if ($this->errmsg != "")
			return false;
			
		// get aspect ratio
		$sizes = getimagesize($this->file_array['tmp_name']);
		if ( (($width != 0) && ($sizes[0] <= $width)) || (($height != 0) && ($sizes[1] <= $height)) ){
			// size is less than desired, so we keep current size (to prevent distortion)
			$new_width = $sizes[0];
			$new_height = $sizes[1];
		}
		else if ($width != 0){
			// resize based on width
			$new_width = $width;
			$new_height = abs($new_width/($sizes[0]/$sizes[1]));
		}
		else{
			// resize based on height
			$new_height = $height;
			$new_width = abs($new_height/($sizes[1]/$sizes[0]));
		}

		// resize the image
		$destimg=ImageCreateTrueColor($new_width,$new_height) or $this->errmsg="Problem in creating image";
		$srcimg=ImageCreateFromJPEG($this->file_array['tmp_name']) or $this->errmsg="Problem in opening source image";
		ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or $this->errmsg="Problem in resizing";
		ImageJPEG($destimg,$this->file_array['tmp_name'],90) or $this->errmsg="Problem in saving";
		imagedestroy($destimg);
		var_dump($destimg);
		var_dump($srcimg);
		var_dump($new_width);
	}
	
	function isError(){
		if ($this->errmsg != "")
			return true;
		else
			return false;
	}
	
	function getErrorMessage(){
		return $this->errmsg;
	}
		
}
?>
Link to comment
Share on other sites

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.