www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help upload file from Form.

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    2

    Help upload file from Form.

    Hi, everyone.

    I want to use one form name is formUpload.html to test upload one file, and result get in result_upload_file.php are: name, type, size and where store about that file. But result is wrong.
    There are my code:

    formUpload.html
    HTML Code:
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    		<title> Form upload file	</title>				
    	</head>	
    	<body>
    		<form action="result_upload_file.php" method="post"
    			enctype="multipart/form-data">
    				<label for="file">Filename:</label>
    				<input type="file" name="file" id="file"><br>
    				<input type="submit" name="submit" value="Submit">
    		</form>
    	</body>
    </html>
    result_upload_file.php
    PHP Code:
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title> Result upload file </title>
        </head>
        <body>
            <?php
                
    if ($_FILES["file"]["error"] > 0)
                    {
                        echo 
    "Error: " $_FILES["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 
    "Stored in: " $_FILES["file"]["tmp_name"];
                    }
            
    ?>                        
        </body>
        
    </html>
    report from system:
    result_error.JPG

    Could you tell me why the result is wrong?

    Thank you.

    p/s:
    1. I store formUpload.html and result_upload_file.php in C:\AppServ\www
    2. My appserv is:
      appServ.JPG

  2. #2
    Join Date
    Aug 2013
    Posts
    2
    I find out my mistake.
    When run form upload file, I double click to file "formUpload.html". In address bar: file:///C:/AppServ/www/formUpload.html
    so it don't send request to server so it show wrong result.
    Corectly, I must open "formUpload.html" from address bar, example: http://localhost/formUpload.html
    after choose file to upload and submit. It show correctly.

    Thanks

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,035
    any file you uploaded will be uploaded to a temporary folder and you will have two move that temporary file to its permanent location.

    You will find at the top of this forum an example of how to upload an image the principle is the same.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

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