|
||||||||||
|
|||||||
| GoogleCommunity Sponsor |
Use coupon "forum" for 50% Off! |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Noogle
![]() Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
File upload with PHP
In later versions of PHP (starting from 4) there is a way of handling file uploads using special global array ($HTTP_POST_FILES), but we describe the older way in this tutorial.
Let's consider that we have this HTML code in file upload form: <form method="post" enctype="multipart/form-data" action="script.php"> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000"> <input type="file" name="userfile"> <input type="submit"> </form> The hidden field MAX_FILE_SIZE (must be specified before <input type=file> tag) is used for setting maximum file size for upload. So the browser will not send the file if its size is more than the value specified here. When form has been submitted PHP creates and fills special variables associated with file transfer data. There is no need in parsing HTTP request manually, PHP would manage it and provide upload variables. Note that variable names consist of two parts and the first part is the same as the specified name of input field in HTML code. Suppose we have this HTML code: <input type="file" name="userfile"> in your PHP script these variables have been automaticaly created: $userfile: File name of temporary file on server machine(created after upload). You can use this variable for copying temporary file into any location to store it. $userfile_name: Name of the file that user located on client machine to upload it into server $userfile_size: Size of uploaded file in bytes. $userfile_type: MIME type of uploaded file. Set only if browser has specified it. Example: "image/gif". There is function to check temporary file name variable. is_uploaded_file($userfile), returns TRUE if $userfile contains the name of temporary uploaded file, and FALSE otherwise. move_uploaded_file($userfile, "/place/to/put/uploaded/file/name.it"): Function used to move temporary file into any location on server machine (of course according to writing rights on that location). Here is the PHP code that stores uploaded file in some location. <? if (is_uploaded_file($userfile)) { move_uploaded_file($userfile, "/place/file.new"); } ?> And also we can do it with open function. <? if (is_uploaded_file($userfile)) { copy($userfile, "/place/file.new"); } ?> |
|
|
|
|
Sponsored Links
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do i upload a file | h4mza | General Discussion | 4 | 10-22-2006 01:52 PM |
| How to Upload URL on Google | Afzaal | All About Google | 1 | 12-13-2005 01:35 PM |
| Gmail upload speeds? | bigjonhayes | Gmail Forum | 7 | 11-30-2005 07:59 PM |
| Video Upload Program | Matrix | All About Google | 2 | 08-15-2005 03:57 AM |
| How to Upload URL on Google | Afzaal | All About Google | 1 | 01-01-1970 11:21 AM |