Page 1 of 1

windows localhost: picture upload problem

Posted: Mon Oct 30, 2006 9:04 am
by lucadg
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,
I am trying to make work locally a site which is online and working.
Both online and locally I use php 4.4.1 and mysql 3.23.58 (server in Linux, local WinXp).
While all seems working, I have a problem with this line not working locally.
When  I try to upload a picture I get the "Sorry, upload picture failed" error (in the code below):

Code: Select all

function UploadPic($MAX_FILE_SIZE,$filename,$file,$ECardRoot_W,$db)
{
	global $apartmentid;
	$fn=$_FILES[$filename]['name'];
	$type=trim($_FILES[$filename]['type']);

	$fnExtName=trim(substr($fn,strrpos($fn,".")));

	$fnExtNameLower=strtolower($fnExtName);

	
	//this is Firefox and IE all OK!
	if(!ereg("\.(jpg|gif|png|JPG|GIF|PNG)$",$fn))
	{
		echo ("Sorry! Only jpg, gif, png extensions are supported! Please convert your pictures to one of this formats");
		exit;
	}
	

	$size=$_FILES[$filename]['size'];
	if ($size>$MAX_FILE_SIZE)
	{
		$systeminfo="Sorry, your picture exceeds the limitation : ".($MAX_FILE_SIZE/1024)." Please use a smaller one<br><P><INPUT TYPE=\"button\" VALUE=\"< Go Back\"
   onClick=\"history.back()\">";
		$db->errorRpt($systeminfo);
	}
	

	$newfn="Apartment".date(y).date(m).date(d).rand();
	$newfntb=$newfn."big".$fnExtNameLower;
	$newfn=$newfn.$fnExtNameLower;
	

	if (!is_dir($ECardRoot_W))
	{
		mkdir($ECardRoot_W, 0777);
	}

	if (!copy($_FILES[$filename]['tmp_name'],$ECardRoot_W."/".$newfntb))
	{
	
	$systeminfo="Sorry, upload picture failed<br><P><INPUT TYPE=\"button\" VALUE=\"< Go Back\"
   onClick=\"history.back()\">";
   
	
		$db->errorRpt($systeminfo);
	}
	//resize
	$tx=GetImageSize($ECardRoot_W."/".$newfntb);
  	if($tx[0]<=$tx[1] and $tx[1]>=100){
   	  $height=100;
  	   $width=intval($height*$tx[0]/$tx[1]);
  	}
  	if($tx[0]>=$tx[1] and $tx[0]>=100){
     $width=100;
     $height=intval($width*$tx[1]/$tx[0]);
	}
  	if($tx[0]<100 and $tx[1]<100){
     $width=$tx[0];
     $height=$tx[1];
  	}
  	 
  	function makethumb2($srcFile,$dstFile,$dstW,$dstH){
           $data=GetImageSize($srcFile,&$info);
           switch($data[2]){
                  case 1:
                       $im=@ImageCreateFromGIF($srcFile);
                       break;
                  case 2:
                       $im=@ImageCreateFromJPEG($srcFile);
                       break;
                  case 3:
                       $im=@ImageCreateFromPNG($srcFile);
                       break;
           }
           $srcW=ImageSX($im);
           $srcH=ImageSY($im);
//----new test begin----
           if(function_exists("imagecopyresampled"))
		   {
				$ni = imagecreatetruecolor($dstW, $dstH);
				imagecopyresampled($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
				}else{
				$ni = imagecreate($dstW, $dstH);
				imagecopyresized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
			}		
			ImageJpeg ($ni,$dstFile);  
//----new test end----
		   /*
		   $ni=ImageCreate($dstW,$dstH);
           ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
           ImageJpeg($ni,$dstFile);
		   */
           // &#1194;รด&#1211;&#938;ImageJpeg($ni);
           // &#1194;&#701;&#892;&#428;&#310;&#1211;&#895;
  	}  	
	makethumb2($ECardRoot_W."/".$newfntb,$ECardRoot_W."/".$newfn,$width,$height);


  return $newfn;
}

I think it may be the php.ini or with the uploadimg folder permission but I have no idea what to touch.
Any idea would be welcomed!
Thank you!

Luca


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Oct 30, 2006 9:09 am
by kettle_drum
Its likely to be an issue with file permissions. The directory is only set to 777 if it doesn't exist and this script creates it. Also make sure that you pass a valid directory path to the function and that your not using a windows based path.

Posted: Tue Oct 31, 2006 2:05 am
by lucadg
Thank you kettle_drum,
I have analyzed the code according to your suggestions but I still don't find the problem.
As this script works fine in the linux system online, where can I set the properties of the folder in windows?
I tried with folder > properties and uncheck the read-only and archive attributes but to no avail.

Also, the path is a linux path, how can I change it to work in Windows?

I am a bit afraid to change to much the code, which will then need again changing before going online.
Is it possible and worth working in a local environment in Windows when the actual output is linux?

Thanks for help!

Luca