upload script question

Discussion in 'PHP' started by izlik, Mar 23, 2010.

  1. #1
    Hello.

    I have a newly installed server wich is running on Debian with Apache2 and php5. the script bellow i wanted to use to upload stuff to my server but i get "Sorry, there was a problem uploading your file." all the time. i have chmoded the files and folder to 777 already., why would i get this ?

    index.php
    <form enctype="multipart/form-data" action="up.php" method="POST">
    Please choose a file: <input name="uploaded" type="file" /><br />
    <input type="submit" value="Upload" />
    </form>
    HTML:
    up.php
    <?php 
    $target = "/var/ww"; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
    {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    } 
    else {
    echo "Sorry, there was a problem uploading your file.";
    }
    ?>
    PHP:
     
    izlik, Mar 23, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    You have forgotten to set the max file zise in the form.

    
    
    <input type="hidden" name="MAX_FILE_SIZE" value="5000" />
    
    
    Code (markup):
     
    stephan2307, Mar 23, 2010 IP
  3. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #3
    Your initial $target should have a trailing forward slash:

    $target = "/var/ww/";

    That's assuming you're not trying to preced all your uploaded file with 'ww' on purpose... ;)
     
    mfscripts, Mar 23, 2010 IP
  4. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #4
    i did that on purpouse cause i dont want a max file size, or do i need to have it ?

    i noticed that afterwards and changed it so my target folder is "$target = "/var/www/test/";" and i still get the same error as in my first post. the folder and files is as said above chmoded 777.
     
    izlik, Mar 23, 2010 IP
  5. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #5
    The only other thing I can think of if that the owner is not the same as php (or doesn't have the same group privillages). It may be worth creating the folder via php (mkdir()) to test. The MAX_FILE_SIZE isn't a requirement.
     
    mfscripts, Mar 23, 2010 IP
  6. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    
    <?php
    $target = "/var/www/upload";
    $targetfile = $target . basename( $_FILES['uploaded']['name']) ;
    $ok=1;
    if(is_writable($target)){
    
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $targetfile))
    {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    }
    else {
    echo "Sorry, there was a problem uploading your file.";
    }
    
    }else{
      echo "Sorry, folder $target is not writable";
    }
    
    ?>
    
    PHP:
     
    guardian999, Mar 23, 2010 IP
  7. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #7
    Probably also need the forward slash in there...

    $targetfile = $target . "/" . basename( $_FILES['uploaded']['name']) ;
     
    mfscripts, Mar 23, 2010 IP
  8. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #8
    yeah, for directory need to adding slash in the end
    
    /var/www/upload/
    
    Code (markup):
     
    guardian999, Mar 23, 2010 IP
  9. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #9
    i got "Sorry, folder /var/www/upload/ is not writable"

    the owner of the folder is called "web" he owns the folder and the files so how come he is not allowed to write into it ?
     
    izlik, Mar 24, 2010 IP