Heim > Backend-Entwicklung > PHP-Tutorial > 演示实现PHP上传文件代码_PHP教程

演示实现PHP上传文件代码_PHP教程

WBOY
Freigeben: 2016-07-15 13:26:57
Original
861 Leute haben es durchsucht

PHP还是比较常用的,相信大家也都知道它的好处,给大家演示一个PHP上传文件代码,下面我们来一起看看吧。通过memory_limit变量来指定单个脚本程序可以使用的最大内存容量变量memory_limit的值应当适当大于post_max_size的值max_execution_time,max_execution_time设置了在强制终止脚本前PHP等待脚本执行完毕的时间,此时间以秒计算。

当脚本进入了一个无限循环状态时此变量非常有用。然而,当存在一个需要很长时间完成的合法活动时(例如上传大型文件),这项功能也会导致操作失败。在这样的情况下必须考虑将此变量值增加,以避免PHP在脚本正在执行某些重要过程的时候将脚本关闭对于linux主机,可能在/etc/httpd/conf.d/access.conf/下面里面还有php.conf文件,这个文件可能会解决一些系统的文件大小限制问题。

PHP上传文件代码

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">file</font></span><span>=$_FILES['userfile1']['tmp_name'];  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">filename</font></span><span>=$_FILES['userfile1']['name'];  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">x</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">rand</font></span><span>(1000,9999);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">tmp_add_pd_path</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"./upload/"</font></span><span>.$x.".jpg";  </span>
</li>
<li class="">
<span>if(!$file||$</span><span class="attribute"><font color="#ff0000">file</font></span><span>=="none"){  </span>
</li>
<li class="alt"><span>echo"no";  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>else{  </span></li>
<li class=""><span>if(move_uploaded_file($file,$tmp_add_pd_path)){  </span></li>
<li class="alt"><span>echo$filename;  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">db</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_connect</font></span><span>("localhost","root","wyh7ye");  </span>
</li>
<li class="alt"><span>mysql_select_db("test",$db);  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">query</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"INSERTintoproduct(name)values('$tmp_add_pd_path')"</font></span><span>;  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">result</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_query</font></span><span>($query,$db);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">pid</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"SELECTLAST_INSERT_ID()"</font></span><span>;  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">pid_result</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_query</font></span><span>($pid,$db);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">rows</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_fetch_array</font></span><span>($pid_result);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">tmp_pid</font></span><span>=$rows[0];  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">tmp_p_type_sql</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"INSERTintot_product(typeid,pid)values('$p_type','$tmp_pid')"</font></span><span>;  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">result</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_query</font></span><span>($tmp_p_type_sql,$db);  </span>
</li>
<li class=""><span>echo"sucess";  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>else{  </span></li>
<li class="alt"><span>echo"false";  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span class="tag"><span class="tag-name">br</span><span class="tag">></span><span class="tag"><span class="tag-name">br</span><span class="tag">></span></span></span></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">db</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_connect</font></span><span>("localhost","root","wyh7ye");  </span>
</li>
<li class=""><span>mysql_select_db("test",$db);  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">query</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"selectnamefromproduct"</font></span><span>;  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">result</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_query</font></span><span>($query,$db);  </span>
</li>
<li class="alt">
<span>while($</span><span class="attribute"><font color="#ff0000">rows</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">mysql_fetch_array</font></span><span>($result)){  </span>
</li>
<li class="">
<span>echo"</span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">imgsrc</font></span><span class="tag-name"><strong><font color="#006699">imgsrc</font></strong></span><span>=".$rows['name']."</span><span class="attribute-value"><font color="#0000ff">width</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">180</font></span><span class="attribute"><font color="#ff0000">180height</font></span><span>=180</span><strong><font color="#006699"><span class="tag">></span><span class="tag"><span class="tag-name">br</span><span class="tag">></span></span></font></strong><span>";  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Nach dem Login kopieren


以上就是详细的PHP上传文件代码,希望对大家有帮助。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446558.htmlTechArticlePHP还是比较常用的,相信大家也都知道它的好处,给大家演示一个PHP上传文件代码,下面我们来一起看看吧。通过memory_limit变量来指定单个...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage