Results 1 to 3 of 3

Thread: Problem uploading single file through php

  1. #1
    Join Date
    Apr 2010

    Problem uploading single file through php

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

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

    //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\">";
    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
    England, UK
    Does the host you are using support PHP?
    n00b like no other

  3. #3
    Join Date
    Aug 2004
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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