File upload problem...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin1983
    New Member
    • Oct 2007
    • 99

    File upload problem...

    Hi, i got a problem while uploading a file. I got a code from www.w3schools.c om. I try the code, but the problem is that, i cannot specify the path where the file should stored. If i want to stored the file as "C:\wamp\www\pr actices" then what will be the syntax.. please to tell me in the following code.
    This is my HTML file
    [HTML]
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator " CONTENT="EditPl us">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Descripti on" CONTENT="">
    </HEAD>

    <BODY>
    <form action="file_up load.php" method="post" enctype="multip art/form-data">
    <label for="file">File Name:</label>
    <input type="file" name="file" id="file"><br>
    <input type="submit" name="submit" value="Upload">
    </form>
    </BODY>
    </HTML>
    [/HTML]


    and this is my php file
    [PHP]
    <?php
    if(($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] <20000))
    {
    if($_FILES["file"]["error"] >0)
    {
    echo "Return Code:" .$_FIELS["file"]["error"]."<br>";
    }
    else
    {
    echo "Upload:" .$_FILES["file"]["name"]."<br>";
    echo "Type:" .$_FILES["file"]["type"]."<br>";
    echo "Size:" .($_FILES["file"]["size"]/1024)."Kb<br>";
    echo "Tmep File" .$_FILES["file"]["tmp_name"]. "<br>";

    if(file_exists( "../robin1/" .$_FILES["file"]["name"]))
    {
    echo $_FILES["file"]["name"]. "already exists.";
    }
    else
    {
    move_uploaded_f ile($_FILES["file"]["tmp_name"],
    "../robin1/".$FILES["file"]["name"]);
    echo "Stored in:". "../robin1/". $_FILES["file"]["name"];

    }
    }
    }
    else
    {
    echo "Invalid file";
    }
    ?>
    when i try this code it give the output as
    Upload:save-petrol.gif
    Type:image/gif
    Size:123.631835 938Kb
    Tmep FileC:\wamp\tmp \phpBD.tmp
    Stored in:../robin1/save-petrol.gif
    but, i dont know where is this file stored. Please help me............
    [/PHP]
  • JeremyMiller
    New Member
    • Sep 2007
    • 69

    #2
    Change this line to indicate your directory:

    [php]
    move_uploaded_f ile($_FILES["file"]["tmp_name"],"../robin1/".$FILES["file"]["name"]);
    [/php]

    Something like

    [php]
    move_uploaded_f ile($_FILES["file"]["tmp_name"],"C:/wamp/www/practices/".$FILES["file"]["name"]);
    [/php]

    should work depending on your server setup and where the script is running from.

    Comment

    • robin1983
      New Member
      • Oct 2007
      • 99

      #3
      When I try that, i got the following error message..
      Upload:save-petrol.gif
      Type:image/gif
      Size:123.631835 938Kb
      Tmep FileC:\wamp\tmp \php5E.tmp

      Warning: move_uploaded_f ile(C:/wamp/www/practices/) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\pra ctices\file_upl oad.php on line 22

      Warning: move_uploaded_f ile() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\ph p5E.tmp' to 'C:/wamp/www/practices/' in C:\wamp\www\pra ctices\file_upl oad.php on line 22
      Originally posted by JeremyMiller
      Change this line to indicate your directory:

      [php]
      move_uploaded_f ile($_FILES["file"]["tmp_name"],"../robin1/".$FILES["file"]["name"]);
      [/php]

      Something like

      [php]
      move_uploaded_f ile($_FILES["file"]["tmp_name"],"C:/wamp/www/practices/".$FILES["file"]["name"]);
      [/php]

      should work depending on your server setup and where the script is running from.

      Comment

      • robin1983
        New Member
        • Oct 2007
        • 99

        #4
        Thanks, i did myself
        Originally posted by robin1983
        When I try that, i got the following error message..
        Upload:save-petrol.gif
        Type:image/gif
        Size:123.631835 938Kb
        Tmep FileC:\wamp\tmp \php5E.tmp

        Warning: move_uploaded_f ile(C:/wamp/www/practices/) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\pra ctices\file_upl oad.php on line 22

        Warning: move_uploaded_f ile() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\ph p5E.tmp' to 'C:/wamp/www/practices/' in C:\wamp\www\pra ctices\file_upl oad.php on line 22

        Comment

        • HongThao
          New Member
          • Oct 2007
          • 4

          #5
          Dear robin1983,
          Your upload code is perfectly except one line is:
          [PHP] move_uploaded_f ile($_FILES["file"]["tmp_name"],
          "../robin1/".$FILES["file"]["name"]);[/PHP]
          Where is your "practices" folder? Is it the same level with your coding file or not? If "practices" folder stay at same level at your php file you only have to change your code like this:
          [PHP] move_uploaded_f ile($_FILES["file"]["tmp_name"],"practices/".$_FILES["file"]["name"]);[/PHP]
          or you can tell me exactly where is "practices" folder, comparing with your php file. I'll tell you its path.

          Good luck

          Comment

          Working...