PUT method supportPHP ManualPrevChapter 18. Handling file uploadsNextPUT method support
PHP provides support for the HTTP PUT method used by clients such
as Netscape Composer and W3C Amaya. PUT requests are much simpler
than a file upload and they look something like this:
1
2 PUT /path/filename.html HTTP/1.1
3
This would normally mean that the remote client would like to save
the content that follows as: /path/filename.html in your web tree.
It is obviously not a good idea for Apache or PHP to automatically
let everybody overwrite any files in your web tree. So, to handle
such a request you have to first tell your web server that you
want a certain PHP script to handle the request. In Apache you do
this with the Script directive. It can be
placed almost anywhere in your Apache configuration file. A
common place is inside a <Directory> block or perhaps inside
a <Virtualhost> block. A line like this would do the trick:
1
2 Script PUT /put.php3
3
This tells Apache to send all PUT requests for URIs that match the
context in which you put this line to the put.php3 script. This
assumes, of course, that you have PHP enabled for the .php3
extension and PHP is active.
Inside your put.php3 file you would then do something like this:
1
2 <? copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?>
3
This would copy the file to the location requested by the remote
client. You would probably want to perform some checks and/or
authenticate the user before performing this file copy. The only
trick here is that when PHP sees a PUT-method request it stores
the uploaded file in a temporary file just like those handled bu the
POST-method.
When the request ends, this temporary file is deleted. So, your PUT
handling PHP script has to copy that file somewhere. The filename
of this temporary file is in the $PHP_PUT_FILENAME variable, and
you can see the suggested destination filename in the $REQUEST_URI
(may vary on non-Apache web servers). This destination filename is
the one that the remote client specified. You do not have to listen
to this client. You could, for example, copy all uploaded files to
a special uploads directory.PrevHomeNextUploading multiple filesUpUsing remote files
Wyszukiwarka
Podobne podstrony:
features file upload put methodfeatures file upload put methodfeatures file upload common pitfallsfeatures file uploadfeatures file uploadfeatures file upload errorsfeatures file uploadfeatures file upload common pitfallsfeatures file upload multiplefeatures file upload multiplefeatures file upload multiplefeatures file upload common pitfallsfile uploadfileman file uploadfunction move uploaded filewięcej podobnych podstron