Home > Backend Development > PHP Tutorial > How to name PHP uploaded images with timestamp and PHP file saving path method

How to name PHP uploaded images with timestamp and PHP file saving path method

WBOY
Release: 2016-07-25 08:52:59
Original
1382 people have browsed it
  1. Image import



  2. < ;/div>
Copy code

2, php code (file upload, name the file with timestamp, save file path in session)

  1. /**
  2. *Mwbe Version1.0
  3. *-----------------------------------------------
  4. *Copy 2013-2014 ylt
  5. *Web: communicate
  6. *-----------------------------------------------
  7. *Author: tao *Data: 2014-7-22
  8. */
  9. header("Content-Type:text/html;charset=utf-8");
  10. //step 1 Use $_FILES['pic ']["error"] Check for errors
  11. if(isset($_GET["action"])=="img"){
  12. if($_FILES["img"]["error"] > 0){
  13. switch($_FILES["img"]["error"]) {
  14. case 1:
  15. echo "";
  16. break;
  17. case 3:
  18. echo "";
  19. break;
  20. case 4:
  21. echo "";
  22. break;
  23. default:
  24. echo "";
  25. }
  26. exit;
  27. }
  28. $maxsize=2000000; //50k
  29. //step 2 Use $_FILES["pic"]["size"] to limit the size unit in bytes 2M=2000000
  30. if($_FILES["img"]["size"] > $maxsize ) {
  31. echo "";
  32. exit;
  33. }
  34. //step 3 Use $_FILES["pic"]["type"] or the file extension Name restriction type MIME image/gif image/png gif png jpg
  35. /* list($dl, $xl) = explode("/", $_FILES["pic"]["type"]);
  36. if($dl !="image"){
  37. echo "Please upload an image, other types of files are not allowed";
  38. exit;
  39. }
  40. */ bbs.it-home.org
  41. $allowtype=array("png", "gif ", "jpg", "jpeg");
  42. $arr=explode(".", $_FILES["img"]["name"]);
  43. $hz=$arr[count($arr)-1] ;
  44. if(!in_array($hz, $allowtype)){
  45. echo "" ;
  46. session_start();
  47. $_SESSION['images'] = $fileimgweb.$randname;
  48. }else{
  49. echo "";
  50. }
  51. }else{
  52. echo"
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template