...

View Full Version : Problem using @move_uploaded_file($tmp_file, $directory);



deshi2003
05-08-2009, 07:28 AM
hey i have completed a site which is named http://www.atneshop.com/ and running well and i used there @move_uploaded_file($tmp_file, $directory) for moving file to my $directory

now i want to develop another site where i would have use same script for uploading and it is fine in my offline server (wamp)

but i test it in online then i got this error:
There was an error moving the uploaded file.

i have attached my code snippet. please check it



function UploadImages($file,$get_file_size,$tmp_file,$directory,$directory_main) // for profile
{
global $chk_img;
$file_type = array("gif","png","jpg","jpeg","GIF","PNG","JPG","JPEG");
$file_info=end(explode(".", $file));

//echo 'tmp = '.$tmp_file.'<br />';
//echo "Size: " . $get_file_size . " bytes<br />";

if($file!='')
{
if(empty($tmp_file) && $get_file_size==0) // Large File Size
{
$msg='Check File Size!!';
}
/*else if(file_exists($directory_main)) // When File Exists
{
$msg='File Already Exists!!';
}*/
else
{
if (in_array($file_info,$file_type)) // When Valid File Type
{
$result = @move_uploaded_file($tmp_file, $directory);

if(empty($result)) // when can't upload file
{
$msg = "There was an error moving the uploaded file.";
}
else
{
$mode = '0777';
chmod ($directory, octdec($mode));
$msg='Information has been saved Successfully!!';
$chk_img=1;

// Resize Checking
list ($width,$height,$type) = @getimagesize($directory);

$max_width=90;
$max_height=90;

if( ($height <=$max_height)&&($width <=$max_width) )
{
$new_width = $width;
$new_height = $height;
}
else if( ($height <$max_height)&&($width >$max_width) )
{
$new_width = $max_width;
$new_height =(int)($max_width* ($height/$width));
}
else if( ($height >$max_height)&&($width <$max_width) )
{
$new_height =$max_height;
$new_width = (int)($max_height*($width/$height));
}
else if ( ($height >$max_height)&&($width >$max_width) )
{
$RH=$height/$max_height;
$RW=$width/$max_width;

if($RH>$RW)
{
$new_height =$max_height;
$new_width = (int)($max_height*($width/$height));
}
else if($RH<$RW)
{
$new_width = $max_width;
$new_height =(int)($max_width* ($height/$width));
}
else
{
$new_width = $max_width;
$new_height = $max_height;
}
}
//echo '<br>$width= '.$width.' $height='.$height;
//echo '<br>$new_width= '.$new_width.' $new_height='.$new_height;

if(($new_width==$width) && ($new_height==$new_height)) // when resize not needed
{
//echo '<br>Yes';
rename($directory,$directory_main) or die('can not rename');
}
else // Resize
{
/* echo '<br>$new_width= '.$new_width.' $new_height='.$new_height; */
$destimg=imagecreatetruecolor($new_width,$new_height) or die('Problem In Creating image');
switch ($type)
{
case 1:
$srcimg=imagecreatefromgif($directory) or die('Problem In opening Source Image');

// keeping transparency
$transparent_index = imagecolortransparent($srcimg);

if ($transparent_index >= 0)
{
imagepalettecopy($srcimg, $destimg);
imagefill($destimg, 0, 0, $transparent_index);
imagecolortransparent($destimg, $transparent_index);
imagetruecolortopalette($destimg, true, 256);
}
// keeping transparency

imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
imagegif($destimg,$directory_main,100) or die('Problem In saving');
imagedestroy($destimg);
unlink($directory);
break;
case 2:
$srcimg=imagecreatefromjpeg($directory) or die('Problem In opening Source Image');
imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($destimg,$directory_main,100) or die('Problem In saving');
imagedestroy($destimg);
unlink($directory);
break;
case 3:
$srcimg=imagecreatefrompng($directory) or die('Problem In opening Source Image');

// keeping transparency
imagealphablending($destimg, false);
imagesavealpha($destimg,true);
$transparent = imagecolorallocatealpha($destimg, 255, 255, 255, 127);
imagefilledrectangle($destimg, 0, 0, $new_width, $new_height, $transparent);
// keeping transparency

imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
imagepng($destimg,$directory_main,9) or die('Problem In saving');
imagedestroy($destimg);
unlink($directory);
}
}
}
}
else
{
$msg='Invalid File Type!!';
}
}
}
return $msg;
}

//-------------------- Image Upload----------------------------//

//-------------------- Image Upload----------------------------//
function UploadImages1($file,$get_file_size,$tmp_file,$directory,$directory_main) // for profile
{
global $chk_img1;
$file_type = array("gif","png","jpg","jpeg","GIF","PNG","JPG","JPEG");
$file_info=end(explode(".", $file));

//echo 'tmp = '.$tmp_file.'<br />';
//echo "Size: " . $get_file_size . " bytes<br />";

if($file!='')
{
if(empty($tmp_file) && $get_file_size==0) // Large File Size
{
$msg='Check File Size!!';
}
/*else if(file_exists($directory_main)) // When File Exists
{
$msg='File Already Exists!!';
}*/
else
{
if (in_array($file_info,$file_type)) // When Valid File Type
{
$result = @move_uploaded_file($tmp_file, $directory);

if(empty($result)) // when can't upload file
{
$msg = "There was an error moving the uploaded file.";
}
else
{
$mode = '0777';
chmod ($directory, octdec($mode));
$msg='Information has been saved Successfully!!';
$chk_img1=1;

// Resize Checking
list ($width,$height,$type) = @getimagesize($directory);

$max_width=800;
$max_height=600;

if( ($height <=$max_height)&&($width <=$max_width) )
{
$new_width = $width;
$new_height = $height;
}
else if( ($height <$max_height)&&($width >$max_width) )
{
$new_width = $max_width;
$new_height =(int)($max_width* ($height/$width));
}
else if( ($height >$max_height)&&($width <$max_width) )
{
$new_height =$max_height;
$new_width = (int)($max_height*($width/$height));
}
else if ( ($height >$max_height)&&($width >$max_width) )
{
$RH=$height/$max_height;
$RW=$width/$max_width;

if($RH>$RW)
{
$new_height =$max_height;
$new_width = (int)($max_height*($width/$height));
}
else if($RH<$RW)
{
$new_width = $max_width;
$new_height =(int)($max_width* ($height/$width));
}
else
{
$new_width = $max_width;
$new_height = $max_height;
}
}
//echo '<br>$width= '.$width.' $height='.$height;
//echo '<br>$new_width= '.$new_width.' $new_height='.$new_height;

if(($new_width==$width) && ($new_height==$new_height)) // when resize not needed
{
//echo '<br>Yes';
rename($directory,$directory_main) or die('can not rename');
}
else // Resize
{
/* echo '<br>$new_width= '.$new_width.' $new_height='.$new_height; */
$destimg=imagecreatetruecolor($new_width,$new_height) or die('Problem In Creating image');
switch ($type)
{
case 1:
$srcimg=imagecreatefromgif($directory) or die('Problem In opening Source Image');

// keeping transparency
$transparent_index = imagecolortransparent($srcimg);

if ($transparent_index >= 0)
{
imagepalettecopy($srcimg, $destimg);
imagefill($destimg, 0, 0, $transparent_index);
imagecolortransparent($destimg, $transparent_index);
imagetruecolortopalette($destimg, true, 256);
}
// keeping transparency

imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
imagegif($destimg,$directory_main,100) or die('Problem In saving');
imagedestroy($destimg);
unlink($directory);
break;
case 2:
$srcimg=imagecreatefromjpeg($directory) or die('Problem In opening Source Image');
imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($destimg,$directory_main,100) or die('Problem In saving');
imagedestroy($destimg);
unlink($directory);
break;
case 3:
$srcimg=imagecreatefrompng($directory) or die('Problem In opening Source Image');

// keeping transparency
imagealphablending($destimg, false);
imagesavealpha($destimg,true);
$transparent = imagecolorallocatealpha($destimg, 255, 255, 255, 127);
imagefilledrectangle($destimg, 0, 0, $new_width, $new_height, $transparent);
// keeping transparency

imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
imagepng($destimg,$directory_main,9) or die('Problem In saving');
imagedestroy($destimg);
unlink($directory);
}
}
}
}
else
{
$msg='Invalid File Type!!';
}
}
}
return $msg;
}

//-------------------- Image Upload----------------------------//
?>

innovatewebs
05-08-2009, 07:37 AM
Please check upload_tmp_dir must have your local folder path in php.ini

deshi2003
05-08-2009, 08:58 AM
Please check upload_tmp_dir must have your local folder path in php.ini


i m using parallels plesk control panel
please tell me where woild i get php.ini

or in which folder i would keep my php.ini file in my domain channelishop.com

please it is urgent for me.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum