Page 1 of 1

move_uploaded_file error...[SOLVED]

Posted: Wed Sep 14, 2005 9:41 am
by kendall
Hegy guys i have a user defined function

Code: Select all

/* Upload Product Images Function */
// upload file
function UploadFile($file,$path){
	if(is_uploaded_file($file)){
		if(move_uploaded_file($file,$path)){
		echo 'ok 2';	return true;
	}	else {echo 'not ok'; return false;}
	}else{
		return false;
	}
}
// end
Im using this function to both upload an image and in modifying that image in another instance

however while i uploaded a image succesffuly, i am having a problem when excuting a "change image" sequence. this is when i am changing the image that i had recently uplaoded

Code: Select all

if($_POST['submit']){
	if($_FILES['file']['tmp_name']){
		// get file info
		$tmp_name = $_FILES['file']['tmp_name'];
		$filename = $_FILES['file']['name'];
		$filesize = $_FILES['file']['size'];
		$filetype = $_FILES['file']['type'];
		if(($filetype != 'image/jpeg') && ($filetype != 'image/pjpeg')){
			$Msg .= 'Error: Could not Upload - '.$filename.' Only JPEG '.$filetype.' formats are accepted';
		}elseif($filesize > FILESIZE){
			$Msg .= 'Error: Could not Upload - '.$filename.' size '.$filesize.' exceeds maximum size '.FILESIZE.'K <br>';
		}else{ // save image and create thumbnail
			// change file name
			// $filename = sprintf("%s/Large/%s.jpg",BASEPATH,$code); // filenames are always going to be the same hence why i am deleteing the files first
			$altfilename = sprintf("%s/Small/_%s.jpg",BASEPATH,$code);
			$dest = sprintf("%s/Large/%s.jpg",BASEPATH,$code);;
			// delete current images''
            @unlink($dest);
            @unlink($altfilename);
            if(!file_exists($dest)) {// delete alt file
			 echo 'ok 1'; $upload = UploadFile($tmp_name,$dest); // upload file
           }else{ $upload = false;}
			if(!$upload){
				$Msg .= 'Error: Could not Upload File! It may already exists! <br>';
			}else{
				'ok 3';
				// create thumbnail and if successful update product image information
				if($thumbnail = ThumbnailImage($code,URL,BASEPATH.'/Small/')){
					$Msg = 'Image for product code '.$code.' uploaded.<br>';
					header('Location: product_detail_info.php?code='.$code.'&Msg='.urlencode($Msg));
					exit;	
etc etc etc.....
while i do get the unlinks to delete the file
when the UploadFile executes the script justs cuts off(no php error warnings) in other words i get the ok 1 and the ok 2 but i do not get to the 'ok3' yet i am not getting the $Msg. if i harded coded the
$upload = false
i would eventuall get the $Msg

Whats going on here
ARRRRRRRRRRRRRRRRRGGGGGGGGGGH!!!!
:oops: :cry:

Posted: Wed Sep 14, 2005 10:10 am
by s.dot

Code: Select all

'ok 3';
perhaps that should be

Code: Select all

echo 'ok 3';
:P