Copy our uploaded file windows system and then delete
PHP as well? No problem – assuming, of course, that the applicant has a digital self-portrait on their computer. In fact, we can upload any type of file from the client to the server.
Files can be uploaded from the browser using an <INPUT> element of type "FILE" within an HTML form. This element is supported by recent versions of both the Netscape and Microsoft browsers. To allow files to be uploaded in this way, the only thing we really need to do is set the ENCTYPE attribute of the form to "multipart/form-data" and the ACTION attribute to our PHP page which will handle the file upload. A simple HTML form for submitting the file might look like this:
Handling the uploaded file is also remarkably easy. The file is saved as phpx (where x is an incrementing integer) in the temporary directory (this directory can be set using the TEMPDIR environment variable). This file is automatically destroyed at the end of the request, so it must be copied on the same page if it is to be retained for later use. The filename is accessible in the same way as all form data, using the name specified in the input element as a PHP variable, in this case $userfile.
We can copy the file to a permanent location using the copy() function which we saw earlier in the
|
---|
|
---|
|
---|
?>
|
---|
In each case, the userfile part of the variable will of course be the name of the FILE<INPUT> element in the HTML form. We can modify upload.php as follows to display the values of these variables for our uploaded file:
|
---|