www.webdeveloper.com
Results 1 to 3 of 3

Thread: Problem uploading single file through php

  1. #1
    Join Date
    Apr 2010
    Posts
    78

    Problem uploading single file through php

    I try to upload a file through php.My code:

    index.php:
    <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <td>
    <table width="100&#37;" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
    <td><strong>Single File Upload </strong></td>
    </tr>
    <tr>
    <td>Select file
    <input name="ufile" type="file" id="ufile" size="50" /></td>
    </tr>
    <tr>
    <td align="center"><input type="submit" name="Submit" value="Upload" /></td>
    </tr>
    </table>
    </td>
    </form>
    </tr>

    upload_ac.php:
    <?php
    //set where you want to store files
    //in this example we keep file in folder upload
    //$HTTP_POST_FILES['ufile']['name']; = upload file name
    //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
    $path= "upload/".$HTTP_POST_FILES['ufile']['name'];
    if($ufile !=none)
    {
    if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
    {
    echo "Successful<BR/>";

    //$HTTP_POST_FILES['ufile']['name'] = file name
    //$HTTP_POST_FILES['ufile']['size'] = file size
    //$HTTP_POST_FILES['ufile']['type'] = type of file
    echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>";
    echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
    echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
    echo "<img src=\"$path\" width=\"150\" height=\"150\">";
    }
    else
    {
    echo "Error";
    }
    }
    ?>



    And finally i changed permission to 777 at these 2 files.But when i try to upload a file i see this message on the page:

    "; //$HTTP_POST_FILES['ufile']['name'] = file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$HTTP_POST_FILES['ufile']['name']."
    "; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."
    "; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."
    "; echo ""; } else { echo "Error"; } } ?>


    and obviously the file hasn't been uploaded.What's the problem?

  2. #2
    Join Date
    Jun 2006
    Location
    England, UK
    Posts
    71
    Does the host you are using support PHP?
    n00b like no other

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Try using the $_FILES array instead of the now-deprecated $HTTP_POST_FILES. See http://www.php.net/manual/en/features.file-upload.php for more info.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles