Page 1 of 1

Problem uploading image

Posted: Thu Jun 04, 2009 5:33 am
by petrosa
Hello,

I have just transfered my webpage to another server, and now the script that uploads an image file doesnt work. All i get is the "Sorry, there was a problem uploading your file." from when the image fails to trasfer.

What might be the source of the problem?

Here is the script

Code: Select all

 
$rand1 = rand();
$target = dirname( __FILE__ )."photos/";
$target1 = $target . $rand1 . basename( $_FILES['photo1']['name']);
 
if (($_FILES['photo1']['name']) == ""){
     $pic1="default.gif";
}
else{
     $pic1 = $rand1 . basename( $_FILES['photo1']['name']);
 
     if (!getimagesize($_FILES['photo1']['tmp_name'])){
          echo "Invalid Image File...";
          exit();
     }
}
 
$name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$address = $_REQUEST['address'];
$lat = $_REQUEST['lat'];
$lng = $_REQUEST['lng'];
$date=time();
 
if (($_FILES['photo1']['name']) != ""){
 
   //Writes the photo to the server
   if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target1))
   {
      //Tells you if its all ok
      echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and  your information has been added to the directory";
 
      //create thumbanail
      $n_width=100; // thumbanil width
      $n_height=100; // thumbnail height
      $thumbs = "thumbnails/";
      $thumbs = $thumbs . $rand1 . basename( $_FILES['photo1']['name']);
 
      //if($_FILES['photo1'][type]=="image/jpeg"){ 
          $im=ImageCreateFromJPEG($target1);
          $width=ImageSx($im); // Original picture width is stored
          $height=ImageSy($im); // Original picture height is stored
          $newimage=imagecreatetruecolor($n_width,$n_height);
          imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
          ImageJpeg($newimage,$thumbs);
          //chmod("$thumbs",0777);
      //}
      // end thumbnail creation
   }
   else {
      //Gives and error if its not
      echo "Sorry, there was a problem uploading your file.";
   } 
}
 

Re: Problem uploading image

Posted: Thu Jun 04, 2009 7:13 am
by susrisha
try to echo $_FILES['error'] in the error reporting statement (sorry the file could not be uploaded) and try to look for the error codec that corresponds to the error.
Mostly the permissions problem

Re: Problem uploading image

Posted: Thu Jun 04, 2009 8:13 am
by petrosa
Thanks for tou answer, i did what you said and i got value 0 from it, which from php manual means "There is no error, the file uploaded with success". The error is printed when the file is being moved to the directory i want, which fails.

I think it might be a permissions error, but when i try to chmod 777 the folder where it gets uploaded from filezilla, i get a command not understood.

Command: SITE CHMOD 777 photos
Response: 500 'SITE CHMOD 777 photos': command not understood

Should i contact the administrator for this, or is there another way around ?

Re: Problem uploading image

Posted: Thu Jun 04, 2009 8:47 am
by mikemike
Is the host Windows or UNIX based? Windows doesn't do chmod'ing

Re: Problem uploading image

Posted: Thu Jun 04, 2009 9:11 am
by petrosa
I am not sure of the server (any easy way to find out?), but if it was windows would i have this problem?

Re: Problem uploading image

Posted: Thu Jun 04, 2009 11:43 am
by McInfo
petrosa wrote:

Code: Select all

$target = dirname( __FILE__ )."photos/";
If your file is located at "/gallery/index.php", $target will be "/galleryphotos/". If you want it to be "/gallery/photos/", you need to change line 3 to

Code: Select all

$target = dirname( __FILE__ )."/photos/";
Edit: This post was recovered from search engine cache.

Re: Problem uploading image

Posted: Thu Jun 04, 2009 1:08 pm
by petrosa
McInfo wrote:
petrosa wrote:

Code: Select all

$target = dirname( __FILE__ )."photos/";
If your file is located at "/gallery/index.php", $target will be "/galleryphotos/". If you want it to be "/gallery/photos/", you need to change line 3 to

Code: Select all

$target = dirname( __FILE__ )."/photos/";
Made the change, but still no luck. I added dirname( __FILE__ ) when i was trying to fix the problem. It still cant move the uploaded file to my directory.

Could it be something about the server settings?