Google Community
Latest Forums Rules Resources
Custom Search

Go Back   Google Community > Webmaster Forums > Web Design, Coding & Programming Forum

GoogleCommunity Sponsor
Cirtex Hosting
Use coupon "forum" for 50% Off!

Reply
 
LinkBack Thread Tools Display Modes
Old 05-05-2005, 11:41 PM   #1 (permalink)
Noogle
 
Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
puccavn
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");
}
?>
puccavn is offline   Reply With Quote
 
Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -8. The time now is 12:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004–2007 Google Community