Whats wrong with my script

Discussion in 'PHP' started by nrodes, Sep 25, 2008.

  1. #1
    I'm trying to make an uploader for my website. I followed some directions I found online.

    Whenever I go to upload it, it says this:


    Warning: move_uploaded_file(/Stuart/cookie.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Program Files\Abyss Web Server\htdocs\Start\upload\upload.php on line 23

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Documents and Settings\Peg Stu and Naji\Local Settings\Temp\php487.tmp' to '/Stuart/cookie.txt' in C:\Program Files\Abyss Web Server\htdocs\Start\upload\upload.php on line 23
    Sorry, there was a problem uploading your file. /I]


    My php script is:

    <?php
    $target = "/Stuart/";
    $target = $target . basename( $_FILES['uploaded']['name']) ;
    $ok=1;

    //This is our size condition
    if ($uploaded_size > 1000000)
    {
    echo "Your file is too large. You might be a Hacker!.<br>";
    $ok=0;
    }


    //Here we check that $ok was not set to 0 by an error
    if ($ok==0)
    {
    Echo "Sorry your file was not uploaded";
    }

    //If everything is ok we try to upload it
    else
    {
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
    {
    echo "The file has been uploaded!";
    }
    else
    {
    echo "Sorry, there was a problem uploading your file.";
    }
    }
    ?>


    I am unfamiliar with php.

    Does anyone know what is wrong?
     
    nrodes, Sep 25, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    let us see your upload form too.
     
    ads2help, Sep 25, 2008 IP
  3. cool_goan

    cool_goan Banned

    Messages:
    250
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can we have a look at the move_uploaded_file function please?
     
    cool_goan, Sep 25, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    move_uploaded_file was a built-in function
     
    ads2help, Sep 25, 2008 IP
  5. cool_goan

    cool_goan Banned

    Messages:
    250
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This could be because of directory permissions. Can you try this?
    <?php

    if(isset($_FILES['uploaded'])){
    $target = "galleries/".basename($_FILES['uploaded']['name']) ;
    print_r($_FILES);

    if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)) echo "OK!";//$chmod o+rw galleries

    }
    else{
    echo "<form enctype='multipart/form-data' action='CodeTool.php' method='POST'>";
    echo "File:<input name='uploaded' type='file'/><input type='submit' value='Upload'/>";
    echo "</form>";
    }

    ?>
     
    cool_goan, Sep 25, 2008 IP