Starting us off, we need to lay down some parameters, for the maximum file size you
want to allow the user to upload and - if it's an image - how high and wide the image can be, else you might get a 1.5MB, 1024 x 768 Jpeg filling up the entire screen!
Next is the path where the resulting file will sit on your server, this should be absolute and PHP needs 'write' permissions to that directory.
Now, we want to list a number of file-types so we can give sensible error messages later on in the script.
This is simply an array indexed by 'content-types' with a value that is human readable
Finally, we want to specify what type of file the user is allowed to upload, for this example, it's an image that we might want to embed in a web page, so we build up an array of related 'image' content-types.
| Comments: |
| upload Progress bar | sam | 02/10/06 04:16 |
| Something barfed...! | Paul Klein | 11/26/05 07:42 |
| RE: Where is set $the_file_type variable | erik | 11/17/05 15:31 |
| Problem Uploading Large Files | naveen | 09/27/05 15:44 |
| RE: PHP image code? | Der Metzgermeister | 09/16/05 19:43 |
| RE: MySQL image upload | sant | 09/15/05 23:09 |
| prevent file overwrite | Adam | 07/17/05 13:39 |
| ? code upload text file, html, .. mutili | sonlam | 05/13/05 05:19 |
| RE: MySQL image upload | jabu | 05/03/05 05:42 |
| my php file is not getting parameter from htm | isnashko | 03/17/05 02:20 |
| RE: sending a mail through linux | Seba | 03/01/05 01:31 |
| sending a mail through linux | viswanath | 02/16/05 05:09 |
| PHP image code? | Howmeister | 02/05/05 07:33 |
| uploading music files .mp3 | madscientest | 01/20/05 19:38 |
| File upload | manar | 12/02/04 04:54 |
| RE: Choosing Multiple Files to Upload at once ? | mike | 07/01/03 16:03 |
| Working Upload Script for restricted mode | Andi | 12/20/02 06:12 |
| RE: Problem Uploading Large Files | remco | 12/09/02 16:14 |
| Problem | Marth164 | 11/30/02 23:06 |
| RE: File upload | sadsad | 11/24/02 14:29 |
| RE: Upload File in Windows easily!!! | Joseph | 11/17/02 10:22 |
| RE: Upload File in Windows easily!!! | Dr_Blackross | 11/07/02 15:29 |
| Uploading file error - no size | Kevin E. | 11/06/02 11:19 |
| Limit CPU or I/O usage while uploading | morgan | 10/01/02 11:05 |
| File upload | liylabagheri | 09/30/02 02:44 |
| know wether the mail send is read or not | karthik | 09/27/02 13:11 |
| RE: Pour les fichiers de grandes tailles | robin | 09/19/02 04:00 |
| Pour les fichiers de grandes tailles | djwo | 09/09/02 05:58 |
| uploading music files | vykhanh | 09/08/02 20:43 |
| RE: "file is in wrong directory" | X-Tatic | 09/06/02 09:18 |
| Filtering and permissions. | Matthew G. Hauge | 08/30/02 15:01 |
| Problem Uploading Large Files | Shane Kelly | 08/29/02 15:22 |
| file types | Jabbamonkey | 08/14/02 14:52 |
| Uploading music files | Corey J. | 08/07/02 19:05 |
| uploadin | Raghuram | 08/05/02 17:41 |
| RE: PHP extension overwritten by..... | Andy Vaughan | 07/31/02 10:36 |
| File Upload...No errors, but no file either. | Myles | 07/30/02 09:06 |
| RE: No errors, but nothing happens | Warren Scott | 07/28/02 16:54 |
| Duplication of file names | Jeremy Brown | 07/28/02 16:23 |
| client dir of uploaded files? | Arnd | 07/15/02 15:44 |
| RE: No errors, but nothing happens | Kurt | 07/13/02 19:38 |
| IIS 5.0/PHP4/Uploading | jason | 07/02/02 17:29 |
| Huge File Upload | Leo | 07/01/02 11:01 |
| width and height values | Spacecat | 06/30/02 22:50 |
| how to easyly upload files from corelldraw | izzy vince | 06/26/02 08:20 |
| No errors, but nothing happens | Harrie | 06/14/02 08:44 |
| cool pice of work!!! | Rene | 06/07/02 15:02 |
| rewards in upload | valesi | 06/03/02 21:52 |
| Check file size before upload? | King | 05/17/02 16:49 |
| File Upload waiting page | mohammed | 05/14/02 19:40 |
| HTTP PUT method, anyone got it working? | Jimmy | 05/14/02 13:07 |
| Beware of symbolic links! | Albe | 04/30/02 13:14 |
| Help me allow only two filetypes! | Jeepha | 04/27/02 23:43 |
| File Uploading.. surely it just...? | Pete | 04/16/02 12:40 |
| fileupload add-on | andrea | 04/15/02 14:01 |
| Script Doesn't Do Anything | T Bunk | 04/11/02 00:33 |
| File upload using PHP | Saravanan | 04/09/02 09:13 |
| wrong datatype for second argument in call to | tnprasad | 04/04/02 07:42 |
| upload in postnuke | bobnt | 04/04/02 06:28 |
| RE: FIle upload | tnprasad | 03/27/02 03:37 |
| RE: Problems uploading... | tnprasad | 03/27/02 03:35 |
| permission probs | tnprasad | 03/27/02 03:26 |
| path to and the permissions...... | tnprasad | 03/27/02 02:57 |
| RE: File Upload | tnprasad | 03/27/02 01:07 |
| Unable to Delete Files | Lyniad | 03/20/02 08:55 |
| image upload | bindiya | 03/20/02 02:34 |
| upload_tmp_dir relative? | Scott MacKay | 03/19/02 12:26 |
| RE: Size Check ? | James | 03/18/02 06:56 |
| RE: undefined variable "task" | James | 03/18/02 06:52 |
| RE: Changing "the_file" name in the form | James | 03/18/02 06:49 |
| RE: File Upload | James | 03/18/02 06:44 |
| File Upload | Nazly | 03/12/02 05:10 |
| Download and open a file | Renato | 03/11/02 09:41 |
| file upload, file name | zorba | 02/18/02 21:25 |
| Changing "the_file" name in the form | jake | 02/14/02 10:41 |
| Downloading perils and headaches | VGM | 02/09/02 23:49 |
| RE: undefined variable "task" | Annie | 02/07/02 22:29 |
| RE: FIle upload | Shashin | 02/04/02 04:37 |
| RE: what's the code for .WMV videos? | Pugzly | 02/02/02 00:22 |
| RE: upload's ok but put's in wrong dir | Pugzly | 02/02/02 00:16 |
| File upload / fopen problem | Jésahel | 01/30/02 09:50 |
| chmod image upload + pdf and other mime types | geecu | 01/24/02 03:39 |
| RE: chmod for image upload | Mike | 01/22/02 22:47 |
| upload's ok but put's in wrong dir | Mr-Duck-Man | 01/22/02 02:23 |
| Web Server | badar | 01/21/02 03:39 |
| Choosing Multiple Files to Upload at once ? | Daven Bodhani | 01/10/02 13:03 |
| Error in uploading file | Tom | 01/01/02 16:50 |
| RE: Browse Button | Mette Schmidt | 12/22/01 18:47 |
| RE: Uploading a known file | Steven Venable | 12/17/01 10:28 |
| How to setup the mySQL in Windows98. I'm new | lkt | 12/14/01 13:20 |
| RE: MySQL | Matt Klich | 12/06/01 19:31 |
| upload directory | TLK | 12/04/01 02:50 |
| How do i Control the FileUpload box with NN | Mayank | 11/30/01 04:35 |
| RE: Write to client machine | Deano | 11/24/01 15:33 |
| Fix to open_basedir restriction - new problem | Johan Natt och Dag | 11/23/01 21:36 |
| Adding new file types to allowed extensions | Grim | 11/10/01 20:55 |
| Mtple Uplding + optional auth (script link) | fandelem | 11/08/01 19:29 |
| Write to client machine | VIMp | 10/24/01 04:50 |
| Upload Multiple Files using array | Justine | 10/11/01 13:30 |
| confusing | Def | 10/10/01 20:10 |
| Choosing Multiple Files to Upload at once ¿? | patricio | 10/08/01 17:59 |
| chmod for image upload? | Quint Campbell | 10/08/01 16:14 |
| pb with uploading exe, rtf | s<alp | 10/05/01 09:38 |
| RE: Where is set $the_file_type variable | Arnand Balsekar | 09/26/01 13:15 |
| Size Check ? | Fissunix | 09/26/01 01:45 |
| RE: Unique File | John | 09/24/01 07:11 |
| Where is set $the_file_type variable | Claudiu Cristea | 09/21/01 14:40 |
| Delete multiple files | Hugo | 09/21/01 12:11 |
| RE: FIle upload | Brian | 09/15/01 04:18 |
| Thanks and a question | Four_D | 09/14/01 14:34 |
| what's the code for .WMV videos? | Swedie | 09/09/01 10:09 |
| RE: Anyone know how to delete files??? | Lukas Pitschl | 09/06/01 01:41 |
| FIle upload | Nandu | 09/03/01 23:30 |
| Renaming uploads | Eggatron | 09/02/01 21:08 |
| RE: multiple file uploading | Jim Ray | 08/27/01 17:41 |
| Re: Add a .pdf to the list | Glenn | 08/24/01 06:49 |
| Files with the same name?! | Sascha Carlin | 08/22/01 05:14 |
| its unsecure to open permission? | elsad | 08/20/01 10:47 |
| bug with fallowed file types fix | Gr-Matic | 08/16/01 22:35 |
| RE: Add a .pdf to the list | Michael | 08/16/01 08:57 |
| how to download in php | Reena | 08/14/01 03:03 |
| Image Uploading. | Shilpa | 08/14/01 02:21 |
| PHP extension overwritten by..... | Sean Shamburger | 08/13/01 20:07 |
| RE: Add a .pdf to the list | Andy | 08/10/01 16:54 |
| Can upload from another machine? | Benny | 08/07/01 01:47 |
| thanks,working fine on www.free.fr provider | Jean-marie | 08/02/01 05:18 |
| RE: multiple file uploading (updated link) | fandelem | 07/19/01 11:56 |
| RE: Add a .pdf to the list | Mike | 07/16/01 03:40 |
| Need Help | Mark Baker | 07/10/01 11:24 |
| Upload File in Windows easily!!! | Michael Hoang | 07/07/01 06:50 |
| RE: easy-upload | ashkan | 07/07/01 01:34 |
| Updated upload code | Bealers | 07/02/01 13:25 |
| RE: Add a .pdf to the list | Nathan Hyde | 07/01/01 22:11 |
| file types | Scott | 07/01/01 15:21 |
| RE: Add a .pdf to the list | Bealers | 07/01/01 02:56 |
| I can't upload on Macs and UNIX OS: Help. | Quino | 06/30/01 09:29 |
| File Upload - ip masquerading | Clemens | 06/30/01 02:11 |
| Uploading Files | Uploading Files | 06/29/01 12:24 |
| embed an image after uploading | Randy | 06/28/01 08:28 |
| RE: Error - Warning: Undefined variable: task... | mike | 06/28/01 00:10 |
| RE: Anyone know how to delete files??? | Tiger | 06/27/01 22:25 |
| i need help on eep files | KEVIN | 06/23/01 05:08 |
| Add a .pdf to the list | Richie TM | 06/21/01 15:11 |
| multiple file uploading | alexandros | 06/19/01 13:06 |
| Big files, long time, no indicator | Erik Chelstad | 06/14/01 13:02 |
| Error - Warning: Undefined variable: task... | Nick | 06/09/01 14:35 |
| RE: Anyone know how to delete files??? | Rich | 06/08/01 12:34 |
| RE: How to Get File Uploading to Work in Windows | Vinod Vyas | 06/05/01 05:34 |
| RE: Browse Button | Gary | 06/04/01 07:01 |
| in Windows it simpy won't work! Why? | Christian Dechery | 06/01/01 13:34 |
| Uploading a known file | Mark S Williams | 05/31/01 13:36 |
| security flaw | chuck | 05/30/01 04:58 |
| RE: Anyone know how to delete files??? | Andreas Bille Brahe | 05/29/01 12:30 |
| RE: to upload csv file into oracle | Wesley Boyd | 05/16/01 23:45 |
| RE: multiple file uploading | fandelem | 05/09/01 04:45 |
| Anyone know how to delete files??? | Alex Tweedie | 05/04/01 16:04 |
| RE: To upload a text file into the Postgresql | shivkumar | 04/17/01 13:40 |
| sending a mail through linux | prakash | 04/12/01 23:27 |
| to upload csv file into oracle | jag | 04/12/01 02:54 |
| change the var | Hoang | 04/11/01 14:33 |
| To upload a text file into the Postgresql | Sandhya | 04/10/01 03:03 |
| Comments on your script | Sergio | 04/09/01 09:06 |
| RE: easy-upload | Dan | 04/05/01 16:40 |
| RE: How to Get File Uploading to Work in Windows | Hoggie | 04/03/01 19:06 |
| RE: How to Get File Uploading to Work in Windows | Julie Skokna | 03/31/01 16:35 |
| RE: safe mode? | Chris | 03/31/01 07:42 |
| easy-upload | gernot | 03/29/01 23:10 |
| code is very bad!!! | jonas | 03/29/01 16:09 |
| safe mode? | Andreas | 03/29/01 10:25 |
| Multiple files... | Eric | 03/28/01 17:07 |
| RE: File Privilege | Franck Chionna | 03/14/01 00:04 |
| RE: Unique File | Franck Chionna | 03/13/01 22:24 |
| RE: why Premission Dennied? | Franck Chionna | 03/13/01 18:51 |
| RE: An Alternative Upload Script Here! | Franck Chionna | 03/13/01 18:46 |
| One file upload function | Dan | 03/12/01 13:08 |
| Page Cannot be displayed. | Lincoln Parks | 03/11/01 18:42 |
| I also keep getting denied | Rulian | 03/05/01 22:43 |
| RE: Upload great except for larger files | Niels | 03/03/01 15:32 |
| "file is in wrong directory" | Kelly | 03/01/01 03:09 |
| why Premission Dennied? | Stone Xu | 02/28/01 02:36 |
| Upload great except for larger files | Peter Michael | 02/27/01 04:41 |
| Unique File | Greg | 02/23/01 07:02 |
| Images | bjw | 02/15/01 16:12 |
| RE: Incorporate this with another form? | Kate Fisher | 02/08/01 12:22 |
| What is mp3 as allowed type | yvo Schaap | 02/06/01 06:27 |
| File Privilege | Alex | 02/06/01 00:30 |
| Upload files | mandar | 02/02/01 01:54 |
| works great, you saved me!!!! | Robert | 02/02/01 00:55 |
| does not work on Explorer (Mac & PC) | Joe Pellicer | 01/31/01 12:37 |
| RE: An Alternative Upload Script Here! | Jay | 01/30/01 14:03 |
| post data gets lost | Christian Dechery | 01/28/01 12:20 |
| RE: Browse Button | Beau | 01/24/01 22:55 |
| Getting the file back on SSL | Beau | 01/24/01 22:52 |
| RE: Browse Button | Greg Sadetsky | 01/17/01 22:30 |
| File 0K ? Check your account quota | Anthony Green | 01/16/01 09:46 |
| Problem of FTP_PUT | jakat | 01/14/01 20:27 |
| Browse Button | Gitte Wange | 01/12/01 05:15 |
| RE: Pop up window showing uploading percentage | Tim Parkin | 01/09/01 12:51 |
| RE: Mac Attack (woops) | fred | 01/03/01 14:32 |
| RE: Mac Attack | fred | 01/03/01 13:18 |
| Mac Attack | phil_whittaker | 01/02/01 07:59 |
| RE: Problems uploading... | Mark | 12/28/00 08:28 |
| nearly there.............. | Baden Powell | 12/27/00 19:43 |
| An Alternative Upload Script Here! | Paul Chambers | 12/27/00 14:11 |
| error in copy | Gerardo Tibana | 12/25/00 17:49 |
| RE: Upload files | Minal | 12/22/00 03:00 |
| alternate FTP upload solution - PLEASE!! | Paul Chambers | 12/20/00 22:31 |
| RE: MySQL | Pete | 12/20/00 17:49 |
| guoyvupobhuio bhi | gyi gi gyigyihttp:/www.the-phreak.subnet. | 12/19/00 10:16 |
| RE: Pop up window showing uploading percentage | Glen Scott | 12/18/00 09:02 |
| Cant get to work | iain white | 12/12/00 12:26 |
| RE: What is the '@' for? | Mark Rompies | 12/12/00 07:08 |
| 0byte files | Simon Aplin | 12/12/00 05:31 |
| What is the '@' for? | Leo | 12/10/00 21:23 |
| 405 Method Not Allowed | Ultratoys | 12/09/00 17:42 |
| Upload files | philip johnson | 12/05/00 13:37 |
| How to Get File Uploading to Work in Windows | Adam Porter | 12/02/00 07:11 |
| RE: I can't make it work :-) | Alexander Ludvig Holm | 11/27/00 07:29 |
| RE: I can't make it work :-) | Yaroslav Dmitriev | 11/26/00 14:17 |
| Try this to solve the //php2 problem | Kyle Tang | 11/26/00 03:18 |
| Pop up window showing uploading percentage | Philip | 11/25/00 23:24 |
| Uploading doesn't work in Windows at all. | Slawa Pidgorny | 11/23/00 16:55 |
| RE: I can't make it work :-) | Graeme | 11/22/00 18:34 |
| problems | preethi | 11/15/00 01:27 |
| RE: I can't make it work :-) | Bill Van Pelt | 11/13/00 13:34 |
| I can't make it work :-) | Alexander Ludvig Holm | 11/10/00 07:05 |
| Document contains no data | Stephan | 11/09/00 10:32 |
| upload differences between NS & IE? | brian lazarz | 11/07/00 11:16 |
| good solution BUT ... | georg gruber | 10/30/00 17:57 |
| How to fix this error | T.L. | 10/19/00 13:59 |
| Send a file to a email! | Philip | 10/12/00 21:01 |
| RE: unable to open C:\\WINDOWS\\TEMP\\php2 ? | harald moun | 10/11/00 10:56 |
| RE: unable to open C:\\WINDOWS\\TEMP\\php2 ? | alexander | 10/10/00 12:38 |
| Excellent! Works; but what's this error msg? | Floyd Baker | 10/09/00 21:21 |
| Excellent! Works; but what's this error msg? | Floyd Baker | 10/09/00 21:21 |
| RE: cant read php file | Katie | 10/05/00 03:05 |
| cant read php file | Doug Smith | 10/03/00 21:39 |
| PHP4 and GIF upload | l3x | 10/02/00 11:48 |
| IIS requires Post Acceptor | Jazz | 10/01/00 23:43 |
| Permission Denied, use FTP | Vinod Vyas | 09/30/00 10:18 |
| RE: Upload to another machine | Carlos Urdaneta | 09/30/00 00:07 |
| Upload segfaults | Adam Goldstein | 09/29/00 02:02 |
| RE: unable to open C:\\WINDOWS\\TEMP\\php2 ? | Jazz | 09/29/00 01:33 |
| RE: validate_upload bug | Adam Goldstein | 09/29/00 01:18 |
| unable to open C:\\WINDOWS\\TEMP\\php2 ? | Otto Cordero | 09/28/00 17:45 |
| Upload to another machine | Jan Huelsberg | 09/28/00 10:56 |
| Error copying upload files from /tmp to other | Rui Amaral Santos | 09/27/00 11:09 |
| RE: Incorporate this with another form? | Mel Miller | 09/25/00 17:22 |
| RE: Resize image instead of regecting it | Glen Davies | 09/21/00 21:14 |
| Resize image instead of regecting it | Glen Davies | 09/21/00 16:15 |
| Resize image instead of regecting it | Glen Davies | 09/21/00 16:15 |
| RE: Thank you!! | Bealers | 09/20/00 18:25 |
| Thank you!! | Fran Miller | 09/20/00 00:01 |
| Thank you!! | Fran Miller | 09/19/00 22:26 |
| RE: Watch out for: "image/bmp" | Bealers | 09/19/00 20:55 |
| RE: Incorporate this with another form? | Robert Davis | 09/19/00 12:45 |
| RE: filename | Joe Garstka | 09/18/00 13:11 |
| filename | Michael McCabe | 09/18/00 06:50 |
| Watch out for: "image/bmp" | Zane Amiralis | 09/17/00 11:10 |
| what about encoding and charsets? | Llorenc Sole | 09/15/00 12:06 |
| validate_upload bug | Jeff Armstrong | 09/13/00 11:14 |
| Incorporate this with another form? | Mel Miller | 09/13/00 04:36 |
| RE: MySQL image upload | chris hughes | 09/12/00 16:43 |
| Problems uploading... | Yann Michel | 09/11/00 15:06 |
| Safe Mode Restrictions | philip olson | 09/10/00 21:32 |
| RE: problemo | Ronald Klip | 09/08/00 09:45 |
| problemo | andri darmawan | 09/08/00 06:52 |
| RE: PHP file upload security vulnerability | Keith | 09/08/00 01:00 |
| RE: MySQL image upload | Ryan Boehm | 09/07/00 23:08 |
| RE: MySQL image upload | Ryan Boehm | 09/07/00 22:53 |
| Really Cool | ashish | 09/07/00 19:27 |
| That is awesome! | Paul Smith | 09/06/00 22:07 |
| That is awesome! | Paul Smith | 09/06/00 22:07 |
| PHP file upload security vulnerability | Nathan Cassano | 09/05/00 19:10 |
| RE: MySQL | Matt Berry | 09/05/00 12:05 |
| MySQL | Ross Poulton | 09/05/00 00:36 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.
|