Home > Backend Development > PHP Tutorial > php automatically creates folders and uploads files

php automatically creates folders and uploads files

WBOY
Release: 2016-07-25 08:53:58
Original
1388 people have browsed it
  1. session_start();

  2. if($_SESSION['Company']=='')
  3. {
  4. //exit();
  5. }
  6. ?>
  7. < ;?php //Upload pictures
  8. $uptypes=array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp',' application/x-shockwave-flash','image/x-png');
  9. $max_file_size=5000000; //Upload file size limit, unit BYTE

  10. $addtime=date("Ymd" ,time());

  11. $testdir="./".$addtime."/";
  12. if(file_exists($testdir)):
  13. else:
  14. mkdir($testdir,0777);
  15. endif;
  16. $destination_folder =$addtime."/"; //Upload file path
  17. $imgpreview=1; //Whether to generate a preview image (1 is generated, others are not generated);
  18. $imgpreviewsize=1/2; //Thumbnail image ratio
  19. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  20. {
  21. if (!is_uploaded_file($_FILES["Pic"][tmp_name]))
  22. //Whether the file exists
  23. {
  24. echo "File does not exist! ";
  25. exit;
  26. }
  27. $file = $_FILES["Pic"];
  28. if($max_file_size < $file["size"])
  29. //Check the file size
  30. {
  31. echo "The file is too big!";
  32. exit;
  33. }
  34. if(!in_array($file["type"], $uptypes))
  35. //Check the file type
  36. {
  37. echo "Only image files or Flash can be uploaded!";
  38. exit;
  39. }
  40. if(!file_exists ($destination_folder))
  41. mkdir($destination_folder);
  42. $filename=$file["tmp_name"];
  43. $image_size = getimagesize($filename);
  44. $pinfo=pathinfo($file["name"]);
  45. $ftype=$pinfo[extension];
  46. $PicName = time().".".$ftype;
  47. $destination = $destination_folder.$PicName;
  48. if (file_exists($destination) && $overwrite != true)
  49. {
  50. echo "The file with the same name already exists! ";
  51. exit;
  52. }
  53. if(!move_uploaded_file ($filename, $destination))
  54. {
  55. echo "Error uploading file! ";
  56. exit;
  57. }
  58. $pinfo=pathinfo($destination);
  59. $fname=$pinfo[basename];
  60. }
  61. ?>$path = dirname(__FILE__);
  62. require_once($path.'/../../Module/Factory.php');
  63. $Factory = new Factory();
  64. $BLL_Trade = $Factory->FactoryTrade();
  65. try {
  66. $Infor = new Infor();
  67. $Infor->Title = $_POST['Title'];
  68. $Infor->Deposit = $_POST['Deposit'];
  69. $Infor->Hire = $_POST[' Hire'];
  70. $Infor->Location = $_POST['Location'];
  71. $Infor->Pic = $destination;
  72. $Infor->Intro = $_POST['Intro'];
  73. if( $_SESSION['MemberId'] ==''){
  74. $Infor->Member->ID='';
  75. }else {
  76. $Infor->Member->ID = $_SESSION['MemberId' ];}
  77. if($_POST['GoodsBarCode'] ==''){
  78. $Infor->Goods->BarCode = 0;
  79. }else {
  80. $Infor->Goods->BarCode = $ _POST['GoodsBarCode'];}
  81. $Infor->Class->ID = 0;//Modify later
  82. $Infor->IssueTime = time();
  83. $Infor->ViewNum = 0;
  84. $ Infor->State = 1; //Undecided now, will be modified in the future
  85. $Infor->Top = 0;
  86. $Infor->Recommend = 0;
  87. $Infor->BookMember->ID = 0;
  88. $Infor->BookTime = 0;
  89. $Infor->BookRemark = 0;
  90. $BLL_Trade->CreateInfor($Infor);
  91. echo 'Publish information successfully! ';
  92. }
  93. catch (Exception $Err){
  94. echo $Err->getMessage();
  95. }
  96. ?>

Copy code

PHP file upload function code example How to set the upload size of PHP files php file upload code collection (example sharing) PHP file upload comprehensive example sharing Examples of php file upload (normal upload and asynchronous upload) Example analysis of php file upload Analysis of php file upload example PHP single file upload example analysis Simple example analysis of php multiple file upload In-depth analysis and understanding of PHP file upload principles php file upload simple example Simple example of php file upload Understand the principles of PHP file upload PHP increases file upload size limit How to set up php to allow large file uploads Share a PHP file upload class php code to implement file upload



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