Upload script error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brian.digipimp@gmail.com

    #1

    Upload script error

    So I wrote this upload script and I keep getting errors and can't get
    it to work. I'm running ubuntu linux and here is my code:

    <html>
    <head>
    <title>Upload </title>
    </head>
    <body>
    <?php


    if(isset ($_POST['submit'])) {
    if (move_uploaded_ file ($_FILES['file']['tmp_name'],
    "../upload/{$_FILES['file']['name']}")) {
    echo 'Your file has been uploaded';}
    else {
    echo 'Your file could not be uploaded because: ';
    switch ($_FILES['file']['error']) {
    case 1:
    echo 'The file exceeds the upload_max_file size setting in php.ini';
    break;
    case 2:
    echo 'The files excees the MAX_FILE_SIZE setting in the HTML form';
    break;
    case 3:
    echo 'The file was only partially uploaded';
    break;
    case 4:
    echo 'No file was uploaded';
    break;
    }}}
    ?>
    <form action="upload. php" enctype="multip art/form-data" method="post">
    <input type="hidden" name="MAX_FILE_ SIZE="50000">
    <input type="file" name="file">
    <input type="submit" name="submit" value="Upload">
    </form>
    </body>
    </html>

    I keep getting 2 errors:

    Warning: move_uploaded_f ile(../upload/whatever.txt): failed to open
    stream: No such file or directory in /var/www/upload.php on line 10

    Warning: move_uploaded_f ile(): Unable to move '/tmp/phpUztFu8' to
    '../upload/whatever.txt' in /var/www/upload.php on line 10

    What does this mean and how do I fix it?

  • Erwin Moller

    #2
    Re: Upload script error

    brian.digipimp@ gmail.com wrote:
    [color=blue]
    > So I wrote this upload script and I keep getting errors and can't get
    > it to work. I'm running ubuntu linux and here is my code:
    >
    > <html>
    > <head>
    > <title>Upload </title>
    > </head>
    > <body>
    > <?php
    >
    >
    > if(isset ($_POST['submit'])) {
    > if (move_uploaded_ file ($_FILES['file']['tmp_name'],
    > "../upload/{$_FILES['file']['name']}")) {[/color]

    You should put a real path to a directory here instead of a relative one.

    And make sure the user that runs as PHP (often apache, nobody, or www-data)
    has write-right in that directory.

    Good luck.

    Regards,
    Erwin Moller

    Comment

    • brian.digipimp@gmail.com

      #3
      Re: Upload script error

      Ok, well theres the problem then... I'm new to this stuff and I dont
      really have any idea how to change directory permissoins. How do I
      check the user and the permissoins? I'm running linux btw

      Comment

      • Sean

        #4
        Re: Upload script error

        ls -l > will print out the directory list with permissions, owner group
        and size etc....

        chmod 777 folder_name > this will allow the folder to be written to

        chown owner:group folder_name > this will change the owner and group of
        the folder name

        Comment

        • Erwin Moller

          #5
          Re: Upload script error

          Sean wrote:
          [color=blue]
          > ls -l > will print out the directory list with permissions, owner group
          > and size etc....
          >
          > chmod 777 folder_name > this will allow the folder to be written to
          >
          > chown owner:group folder_name > this will change the owner and group of
          > the folder name[/color]

          I would not advocate chmod 777 on any directory you want to keep for
          yourself.
          It opens the directory for read/write for everybody with access to the same
          machine.
          In a shared hosting environment this is not very safe..

          It may be better to have a little chit-chat with your provider and ask him
          for a solution with an extra group that contains the original user and
          www-data (or whatever apache is running as).
          Then change to 774 <dirname>
          or even
          770

          Regards,
          Erwin Moller

          Comment

          Working...