move_uploaded_file error...[SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

move_uploaded_file error...[SOLVED]

Post 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:
Last edited by kendall on Wed Sep 14, 2005 1:11 pm, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

'ok 3';
perhaps that should be

Code: Select all

echo 'ok 3';
:P
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply