Demo implementation of PHP file upload code_PHP tutorial

WBOY
Release: 2016-07-15 13:26:57
Original
842 people have browsed it

PHP is still commonly used, and I believe everyone knows its benefits. I will show you a PHP file upload code. Let’s take a look. Use the memory_limit variable to specify the maximum memory capacity that a single script program can use. The value of the variable memory_limit should be appropriately greater than the value of post_max_size max_execution_time. max_execution_time sets the time that PHP waits for the script to be executed before forcibly terminating the script. This time is calculated in seconds.

This variable is useful when the script enters an infinite loop. However, this feature can also cause the operation to fail when there is a legitimate activity that takes a long time to complete (such as uploading a large file). In such cases, you must consider increasing the value of this variable to prevent PHP from shutting down the script when the script is executing some important processes. For Linux hosts, it may be under /etc/httpd/conf.d/access.conf/ There is also the php.conf file, which may solve the file size limit problem of some systems.

PHPUpload file code

<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 class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>file</FONT></SPAN><SPAN>=$_FILES['userfile1']['tmp_name'];  </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>filename</FONT></SPAN><SPAN>=$_FILES['userfile1']['name'];  </SPAN></SPAN><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></SPAN><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></SPAN><LI class=""><SPAN>if(!$file||$</SPAN><SPAN class=attribute><FONT color=#ff0000>file</FONT></SPAN><SPAN>=="none"){  </SPAN></SPAN><LI class=alt><SPAN>echo"no";  </SPAN><LI class=""><SPAN>}  </SPAN><LI class=alt><SPAN>else{  </SPAN><LI class=""><SPAN>if(move_uploaded_file($file,$tmp_add_pd_path)){  </SPAN><LI class=alt><SPAN>echo$filename;  </SPAN><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></SPAN><LI class=alt><SPAN>mysql_select_db("test",$db);  </SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>tmp_pid</FONT></SPAN><SPAN>=$rows[0];  </SPAN></SPAN><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></SPAN><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></SPAN><LI class=""><SPAN>echo"sucess";  </SPAN><LI class=alt><SPAN>}  </SPAN><LI class=""><SPAN>else{  </SPAN><LI class=alt><SPAN>echo"false";  </SPAN><LI class=""><SPAN>}  </SPAN><LI class=alt><SPAN>}  </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></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></SPAN><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></SPAN><LI class=""><SPAN>mysql_select_db("test",$db);  </SPAN><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></SPAN><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></SPAN><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></SPAN><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><SPAN class=tag-name>br</SPAN><SPAN class=tag>></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>
Copy after login


The above is the detailed PHP file upload code, I hope it will be helpful to everyone.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446558.htmlTechArticlePHP is still relatively commonly used. I believe everyone knows its benefits. I will show you a PHP file upload code. Let’s take a look below. Use the memory_limit variable to specify a single...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template