SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: File upload

  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File upload

    Hey guys,
    I need some help with this script:
    PHP Code:
    <?php
    $err 
    24;
    if (
    $err!=24) echo 'something';
    elseif (
    $_FILES['file']['error'] == 0) {
      
    $filename basename($_FILES['file']['name']);
      
    $ext substr($filenamestrrpos($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); 
              }
    }
    ?>
    It works fine locally on a Win XP machine, but when I upload it to a Linux machine it always returns the error message.

    Also, I'm thinking of having this script run on a subdomain name. Is it possible to have the uploaded file on the main domain name???

    Thanks for your time in advance...

  2. #2
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok so i figured it out:

    PHP Code:
    if ((move_uploaded_file($_FILES['file']['tmp_name'] , "/img/" $_FILES["file"]["name"]))) { 
    changed to:
    PHP Code:
    if ((move_uploaded_file($_FILES['file']['tmp_name'] , "img/" $_FILES["file"]["name"]))) { 
    removed / in front of the upload folder and CHMOD 777 the folder on the server...

    Is this a secured way to do it???

    Also, how can i make the file upload into a specific folder that is on the main domain (Eg: http://www.maindomain.com/img/)

    The script is currently running on a subdomain

  3. #3
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, so i was able to get the full path for both by using getcwd();

    path1 (domain path): /var/www/vhosts/mydomain.com/httpdocs/img/
    path2 (subdomain): /var/www/vhosts/mydomain.com/subdomains/sub/httpdocs/img/

    now the weird part is that if i use path2 it works fine and it uploads the file into the /img/ folder on the subdomain. However if i use path1 i get: "Error: A problem occurred during file upload!"
    I've set both uploading folders to chmod 777

    Any ideas?

  4. #4
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's permission problem and you can't move something twice, try copy after the file is moved to the first path.
    my mobile portal
    ghiris.ro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •