Home  >  Article  >  Backend Development  >  演示实现PHP上传文件代码_PHP教程

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

WBOY
WBOYOriginal
2016-07-15 13:26:57749browse

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上传文件代码

  1. php 
  2. $file=$_FILES['userfile1']['tmp_name'];  
  3. $filename=$_FILES['userfile1']['name'];  
  4. $x=rand(1000,9999);  
  5. $tmp_add_pd_path="./upload/".$x.".jpg";  
  6. if(!$file||$file=="none"){  
  7. echo"no";  
  8. }  
  9. else{  
  10. if(move_uploaded_file($file,$tmp_add_pd_path)){  
  11. echo$filename;  
  12. $db=mysql_connect("localhost","root","wyh7ye");  
  13. mysql_select_db("test",$db);  
  14. $query="INSERTintoproduct(name)values('$tmp_add_pd_path')";  
  15. $result=mysql_query($query,$db);  
  16. $pid="SELECTLAST_INSERT_ID()";  
  17. $pid_result=mysql_query($pid,$db);  
  18. $rows=mysql_fetch_array($pid_result);  
  19. $tmp_pid=$rows[0];  
  20. $tmp_p_type_sql="INSERTintot_product(typeid,pid)values('$p_type','$tmp_pid')";  
  21. $result=mysql_query($tmp_p_type_sql,$db);  
  22. echo"sucess";  
  23. }  
  24. else{  
  25. echo"false";  
  26. }  
  27. }  
  28. ?> 
  29. br>br>br>br> 
  30. php 
  31. $db=mysql_connect("localhost","root","wyh7ye");  
  32. mysql_select_db("test",$db);  
  33. $query="selectnamefromproduct";  
  34. $result=mysql_query($query,$db);  
  35. while($rows=mysql_fetch_array($result)){  
  36. echo"imgsrcimgsrc=".$rows['name']."width=180180height=180>br>";  
  37. }  
  38. ?> 


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


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446558.htmlTechArticlePHP还是比较常用的,相信大家也都知道它的好处,给大家演示一个PHP上传文件代码,下面我们来一起看看吧。通过memory_limit变量来指定单个...
Statement:
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