Home arrow PHP arrow Page 4 - Stream Me Up, Scotty (part 2)

Upsa-daisy! - PHP

You've already seen how PHP4's FTP functions can help youinteract with files on a remote server. In this article, learn how to usePHP's other file and directory manipulation functions, and build anequivalent application that demonstrates the difference between the twoapproaches.

  1. Stream Me Up, Scotty (part 2)
  2. Looking Around
  3. To Create And Destroy
  4. Upsa-daisy!
  5. Remote Control
  6. The Application
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 2
November 29, 2000

print this article


PHP also allows you to upload files via HTTP, assuming you have an RFC-1867 compliant browser (if you're using a relatively recent version of either Internet Explorer or Netscape Navigator, you're OK). There are two components to this: the form which accepts the file upload, and the server-side script which checks the file and decides where to put it.

Let's start with the form first.

<html> <head> </head> <body> <center> <form enctype="multipart/form-data" action="upload.php4" method=post> Enter file name <input name="upfile" type="file"> <br> <input type="submit" value="Beam Me Up, Scotty"> </form> </center> </body> </html>
There are two points of note here: the form's encoding type of "multipart/form-data", and the file browse button <input name="upfile" type="file">, which displays a directory browser and lets you select a file from your system. Once you're done, hit the Submit button and let the script "upload.php4" take over.

Before I take you through "upload.php4", though, you should be aware that when a file is uploaded in this manner, PHP typically creates four variables, each of them containing the name of the file field as prefix. In the example above, these variables would be:

$upfile_name - the original name of the file

$upfile - the temporary name assigned to the file by PHP once it has been successfully uploaded

$upfile_size - the size of the file

$upfile_type - the MIME file type

You should also note that once the file is uploaded, it is stored in the temporary file area on the remote computer, and your script needs to move it out of there to your desired destination directory. If this does not happen, the file will be automatically deleted.

As stated in the first part of this article, these variables are also available in the $HTTP_POST_FILES array, and it is recommended that you use this array to access the variables above (rather than accessing them directly) for greater security.

This article copyright Melonfire 2000. All rights reserved.

>>> More PHP Articles          >>> More By Vikram Vaswani, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: