Page 1 of 1

File upload

Posted: Mon Jun 09, 2008 10:29 am
by cnpsys
hey guys,
i was wondering if anyone can help me with this:

Code: Select all

<?php
$err = 24;
if ($err!=24) echo 'something';
elseif ($_FILES['file']['error'] == 0) {
  $filename = basename($_FILES['file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
 $type=$_FILES["file"]["type"];
 $size=$_FILES["file"]["size"];
  $ok=1;
  $info = getimagesize($_FILES['file']['tmp_name']);
  //echo $info[0].'   '.$info[1];
//  echo $type;
  if (!(($ext=="jpg") || ($ext=="gif"))) 
        {$ok=0;
         $err=1;
        }
  elseif (!(($type=="image/pjpeg") || ($type=="image/gif")))
       { $ok=0;
         $err=2;
        }
  elseif ($size > 200000) 
        {$ok=0;
         $err=3; 
         }
  elseif (($info[0]!=800) || ($info[1]!=600))
      {$ok=0;
       $err=4;
       };   
  if ($ok==1) 
   {
        if ((move_uploaded_file($_FILES['file']['tmp_name'] , "/img/" . $_FILES["file"]["name"]))) {
             echo "File saved";
              } 
        else { echo "Error: A problem occurred during file upload!"; }
    }
     else { header('Location: add_file.php?err='.$err); 
          }
}
?>
 
Every time i try to upload a file i get Error: A problem occurred during file upload!
Now the funny thing is... it works fine locally on my Windows XP machine but when i try to run it on a Linux machine it gives me the error message.

And one more thing:
I'm planning on having this run on a subdomain. Is it possible to have the files uploaded into a /img/ folder on the main domain name???

Thanks for your time guys and hope someone is willing to shed some light for me...

Re: File upload

Posted: Mon Jun 09, 2008 11:25 am
by aceconcepts
Try including basename on line 31 and remove the 2nd bracket after "if"

Code: Select all

 
//change
if ((move_uploaded_file($_FILES['file']['tmp_name'] , "/img/" . $_FILES["file"]["name"]))) {
 
//to
if (move_uploaded_file($_FILES['file']['tmp_name'] , "/img/" . basename($_FILES["file"]["name"]))) {
 
Technically a sub domain is simply a sub directory to "public_html/" on your server

Re: File upload

Posted: Mon Jun 09, 2008 11:33 am
by cnpsys
hi ace,
thx for your quick reply...
so i tried changing that line to:

Code: Select all

if (move_uploaded_file($_FILES['file']['tmp_name'] , "/img/" . basename($_FILES["file"]["name"]))) {
still... same output:
Error: A problem occurred during file upload!

Re: File upload

Posted: Mon Jun 09, 2008 12:06 pm
by cnpsys
ok so i figured it out:

changed:

Code: Select all

if (move_uploaded_file($_FILES['file']['tmp_name'] , "/img/" . basename($_FILES["file"]["name"]))) {
to:

Code: Select all

if (move_uploaded_file($_FILES['file']['tmp_name'] , "img/" . basename($_FILES["file"]["name"]))) {
removed the / in front of the img folder and chmod 777 the folder on the server.
is this secured???? 755 didnt work.

How do i make the upload put the file on the main domainname???
i tried http://domainname.com/img/ and it didnt work.
the script is currently running on a subdomain name

Re: File upload

Posted: Tue Jun 10, 2008 3:15 am
by aceconcepts
If you just declare the absolute path from the root to where you want to upload to, then it should be fine.

Like I said before, a sub domain is just a sub directory of public_html/