Demo implementation php upload file code _php tutorial

Source: Internet
Author: User
PHP is still more commonly used, I believe we all know its benefits, to show you a PHP upload file code, let's take a look at it. Use the Memory_limit variable to specify a maximum memory capacity variable that can be used by a single script memory_limit value should be appropriately greater than the value of Post_max_size Max_execution_time,max_execution_ Time sets how long PHP waits for the script to complete before forcing the script to terminate, which is calculated in seconds.

This variable is useful when the script enters an infinite loop state. However, this feature also causes the operation to fail when there is a legitimate activity that takes a long time to complete, such as uploading large files. In such cases, you must consider increasing the value of this variable to avoid PHP closing the script for Linux hosts when the script is performing some important process, possibly in/etc/httpd/conf.d/access.conf/ There is also a php.conf file, which may solve some system file size limitation issues.

PHP upload file code

 
 
  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 " < imgsrc imgsrc = ". $rows [' name ']." width = the 180height =180 ><br> ";
  37. }
  38. ?>


The above is the detailed PHP upload file code, we hope to be helpful.


http://www.bkjia.com/PHPjc/446558.html www.bkjia.com true http://www.bkjia.com/PHPjc/446558.html techarticle PHP is still more commonly used, I believe we all know its benefits, to show you a PHP upload file code, let's take a look at it. Specify a single by Memory_limit variable ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.