SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP upload script for uploading word documents

    Hi
    I am trying to write a php script for uploading a word doc resume file via a form
    But I keep getting a invalid file error

    here is my html form

    <html>
    <body>
    <form action="test.php" enctype="multipart/form-data" method="post"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form>
    </body>
    </html>


    Here is the php script

    <?php
    $target = "upload/";
    $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.";
    }
    ?>


    I have not changed any names in the php script above .Only thing I did was create a upload folder in my directory on my server .But I keep getting the error Sorry there was a problem uploading your file


    Please reply ASAP

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    if (isset($_POST['submit']))
    {
        
    $target "upload/";
        
    $target $target basename($_FILES['uploaded']['name']);
        
    $ok 1;
        if (
    move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
        {
            echo 
    "The file " basename($_FILES['uploaded']['name']) . " has been uploaded";
        }
        else
        {
            echo 
    "Sorry, there was a problem uploading your file.";
        }
    }

    ?>
    <html>
    <body>
    <form action="test.php" enctype="multipart/form-data" method="post"> 
    Please choose a file: 
    <input name="uploaded" type="file" /><br /> 
    <input type="submit" name="submit" value="Upload" />
    </form>
    </body>
    </html>
    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
  •