![]() |
|
#1
|
|||
|
|||
Upload ScriptI am looking for a script to upload a file to the server using http. It will be pictures in particular.
<input type="file"> <= This is where the filename will be i need a script to get this file on a local computer and upload it to the host. |
|
#2
|
||||
|
||||
|
I would check out www.hotscripts.com
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business. |
|
#3
|
||||
|
||||
|
Why go any further, when you can get your help for uploading a file with PHP, right here!
The HTML Image Upload Form The first thing you need, in order to upload a file, is an HTML page that has a a FORM with enctype="multipart/form-data", an input tag of type="file", and an input of type="submit" (of course). Consider the following HTML form to upload the file: HTML Code:
Some Initial Considerations The key thing to consider, before using this script is where your destination files will be kept. You will need to make sure that the directory you set the IMAGES_PATH constant to has proper permissions to be writable by your scripts. You may have to set this directory to have permissions set to '777'. Also, if you have errors due to an initial default limit, set during your installation of PHP, you can fix this by having the following setting in a .htaccess file, where your script resides: This will make sure you have practically no limit on filesize. To limit the filesize, lower the number listed below, or limit it within your PHP script by checking the $_FILES:['your_file_input_field_name_that_you_use_in_your_H TML_code']['size'] value. Code:
You can also set where you want temporary files saved, by using the following setting in your .htaccess file. I had to use this once when a hosting provider made the servers tmp directory unwritable by my scripts. Code:
The Image Upload PHP Script The following script may be used to upload a file, using PHP. I've incorporated some simple error handling. PHP Code:
Concluding Thoughts For Our PHP Image Upload Script In order to understand how this works, you should understand that when an HTML form is posted of the type we used in this example, an input field of type="FILE" will tell the HTML server that a file is to be posted to the server's memory and transfered to the harddrive in its TMP directory. PHP allows for you to access details of the transfer by using the $_FILE server array variable. The $_FILE array variable has the following key fields: For details of your file transfer, you could always list the elements of the $_FILE array by using the print_r($_FILE) command. Once the attempt to transfer the file to the harddrive of the server, our script checks to see if the $_FILE['name'] is set in the $filename, and then does the processing to check if the filename is of a recognized type. We could have checked this using the $_FILE array, but checking the filename, itself, ensures that your users are uploading files with proper suffixes. I hope that this helps explain some of the mystery behind the process of uploading a file using PHP. This tutorial only covers the very basic process in order to explain it to a beginner. A more advanced example would illustrate the usage of a PHP Image Upload class, and offer the capability of storing filenames in a database or listing the directory in a graphical format. The possibilities are endless. |
|
#4
|
|||
|
|||
|
It wont overwrite old files so?
|
|
#5
|
||||
|
||||
|
You could probably modify the script to ask if you want to overwrite a file, before overwriting. Otherwise, when you use move_uploaded_file, the file will get overwritten.
|
|
#6
|
|||
|
|||
|
This helps a lot, thanks.
|
|
#7
|
|||
|
|||
|
I know this thread is really old so I'm sorry for digging it up again but it deals with almost exactly what I need.
JasonMichael, could you expand on the above script for me a little bit more? What I need is to rename the image with the last row id (auto_increment) of my db table "properties" and then store the file name in the "mainphoto" column of that row. So if the last row id in my db is 10 and someone uploads mypic.gif then it would be uploaded as 10.gif and the value "10.gif" would be stored in the "mainimage" field of row id 10. Hope that makes sense. Thanks in advance for your help. Quote:
|
Recent GIDBlog
Toyota - 2008 July Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two virtual hosts, cgi script behaves differently on each | blimbo | Apache Web Server Forum | 0 | 04-Aug-2004 09:35 |
| JavaScript Tutorial Part 1 | pcxgamer | Web Design Forum | 2 | 01-Dec-2003 09:16 |
| upload thumbnail | zuzupus | MySQL / PHP Forum | 5 | 27-Aug-2003 07:12 |
| sms web sender script | jrobbio | MySQL / PHP Forum | 1 | 11-Apr-2003 12:19 |
| VALIDATING file types on an PHP upload script? | JdS | MySQL / PHP Forum | 0 | 02-Jan-2003 07:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The