⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 features.file-upload.put-method.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>PUT method support</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.file-upload.html">Handling file uploads</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.remote-files.html">Using remote files</a></div> <div class="up"><a href="features.file-upload.html">Handling file uploads</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="features.file-upload.put-method" class="sect1">   <h2 class="title">PUT method support</h2>   <p class="para">    PHP provides support for the HTTP PUT method used by some clients to store    files on a server.    PUT requests are much simpler than a file upload using POST requests    and they look something like this:    <div class="informalexample">     <div class="example-contents"><div class="cdata"><pre>PUT /path/filename.html HTTP/1.1</pre></div>     </div>    </div>   </p>   <p class="para">    This would normally mean that the remote client would like to save    the content that follows as: <var class="filename">/path/filename.html</var> 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 <em class="emphasis">Script</em> directive.  It can be    placed almost anywhere in your Apache configuration file.  A    common place is inside a &lt;Directory&gt; block or perhaps inside    a &lt;VirtualHost&gt; block.  A line like this would do the trick:    <div class="informalexample">     <div class="example-contents"><div class="cdata"><pre>Script PUT /put.php</pre></div>     </div>    </div>   </p>   <p class="simpara">    This tells Apache to send all PUT requests for URIs that match the    context in which you put this line to the put.php script. This    assumes, of course, that you have PHP enabled for the .php    extension and PHP is active. The destination resource for all PUT     requests to this script has to be the script itself, not a filename the    uploaded file should have.   </p>   <p class="simpara">    With PHP you would then do something like the following in    your put.php. This would copy the contents of the uploaded file to the    file <var class="filename">myputfile.ext</var> on the server.    You would probably want to perform some checks and/or    authenticate the user before performing this file copy.   </p>   <p class="para">    <div class="example">     <p><b>Example #1 Saving HTTP PUT files</b></p>     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;PUT&nbsp;data&nbsp;comes&nbsp;in&nbsp;on&nbsp;the&nbsp;stdin&nbsp;stream&nbsp;*/<br /></span><span style="color: #0000BB">$putdata&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://input"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Open&nbsp;a&nbsp;file&nbsp;for&nbsp;writing&nbsp;*/<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"myputfile.ext"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Read&nbsp;the&nbsp;data&nbsp;1&nbsp;KB&nbsp;at&nbsp;a&nbsp;time<br />&nbsp;&nbsp;&nbsp;and&nbsp;write&nbsp;to&nbsp;the&nbsp;file&nbsp;*/<br /></span><span style="color: #007700">while&nbsp;(</span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$putdata</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1024</span><span style="color: #007700">))<br />&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Close&nbsp;the&nbsp;streams&nbsp;*/<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$putdata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>   </p>  </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.file-upload.html">Handling file uploads</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.remote-files.html">Using remote files</a></div> <div class="up"><a href="features.file-upload.html">Handling file uploads</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -