Php automatically creates folders and uploads files

Source: Internet
Author: User
Php automatically creates folders and uploads files

  1. Session_start ();

  2. If ($ _ SESSION ['Company'] = '')
  3. {
  4. // Exit ();
  5. }
  6. ?>
  7. $ Uptypes = array ('image/jpg ', 'image/jpeg', 'image/png ', 'image/pjpeg', 'image/GIF ', 'image/bmp ', 'application/x-shockwave-Flash', 'image/x-png ');
  8. $ Max_file_size = 5000000; // size limit of uploaded files, in bytes

  9. $ Addtime = date ("Ymd", time ());

  10. $ Testdir = "./". $ addtime ."/";
  11. If (file_exists ($ testdir )):
  12. Else:
  13. Mkdir ($ testdir, 0777 );
  14. Endif;
  15. $ Destination_folder = $ addtime. "/"; // upload file path
  16. $ Imgpreview = 1; // whether to generate a preview image (1 is generated, others are not generated );
  17. $ Imgpreviewsize = 1/2; // Thumbnail ratio
  18. If ($ _ SERVER ['request _ method'] = 'post ')
  19. {
  20. If (! Is_uploaded_file ($ _ FILES ["Pic"] [tmp_name])
  21. // Whether a file exists
  22. {
  23. Echo "the file does not exist! ";
  24. Exit;
  25. }
  26. $ File = $ _ FILES ["Pic"];
  27. If ($ max_file_size <$ file ["size"])
  28. // Check the file size
  29. {
  30. Echo "the file is too large! ";
  31. Exit;
  32. }
  33. If (! In_array ($ file ["type"], $ uptypes ))
  34. // Check the file type
  35. {
  36. Echo "only Image files or Flash files can be uploaded! ";
  37. Exit;
  38. }
  39. If (! File_exists ($ destination_folder ))
  40. Mkdir ($ destination_folder );
  41. $ Filename = $ file ["tmp_name"];
  42. $ Image_size = getimagesize ($ filename );
  43. $ Pinfo = pathinfo ($ file ["name"]);
  44. $ Ftype = $ pinfo [extension];
  45. $ PicName = time (). ".". $ ftype;
  46. $ Destination = $ destination_folder. $ PicName;
  47. If (file_exists ($ destination) & $ overwrite! = True)
  48. {
  49. Echo "the file with the same name already exists! ";
  50. Exit;
  51. }
  52. If (! Move_uploaded_file ($ filename, $ destination ))
  53. {
  54. Echo "an error occurred while uploading files! ";
  55. Exit;
  56. }
  57. $ Pinfo = pathinfo ($ destination );
  58. $ Fname = $ pinfo [basename];
  59. }
  60. ?> $ Path = dirname (_ FILE __);
  61. Require_once ($ path. '/.../Module/Factory. php ');
  62. $ Factory = new Factory ();
  63. $ BLL_Trade = $ Factory-> FactoryTrade ();
  64. Try {
  65. $ Infor = new Infor ();
  66. $ Infor-> Title =$ _ POST ['title'];
  67. $ Infor-> Deposit = $ _ POST ['posit'];
  68. $ Infor-> Hire =$ _ POST ['hire '];
  69. $ Infor-> Location = $ _ POST ['location'];
  70. $ Infor-> Pic = $ destination;
  71. $ Infor-> Intro =$ _ POST ['Intro'];
  72. If ($ _ SESSION ['memberid'] = ''){
  73. $ Infor-> Member-> ID = '';
  74. } Else {
  75. $ Infor-> Member-> ID = $ _ SESSION ['memberid'];}
  76. If ($ _ POST ['goodsbarcode'] = ''){
  77. $ Infor-> Goods-> BarCode = 0;
  78. } Else {
  79. $ Infor-> Goods-> BarCode =$ _ POST ['goodsbarcode'];}
  80. $ Infor-> Class-> ID = 0; // modify later
  81. $ Infor-> IssueTime = time ();
  82. $ Infor-> ViewNum = 0;
  83. $ Infor-> State = 1; // It is not fixed now and will be modified later
  84. $ Infor-> Top = 0;
  85. $ Infor-> Recommend = 0;
  86. $ Infor-> BookMember-> ID = 0;
  87. $ Infor-> BookTime = 0;
  88. $ Infor-> BookRemark = 0;
  89. $ BLL_Trade-> CreateInfor ($ Infor );
  90. Echo 'Publish information successful! ';
  91. }
  92. Catch (Exception $ Err ){
  93. Echo $ Err-> getMessage ();
  94. }
  95. ?>

Php file upload function code example php file upload size setting method php file upload code Daquan (instance sharing) php file Upload comprehensive example sharing php file upload (normal upload and asynchronous upload) example: php file upload example analysis php single file upload example analysis php multi file Upload simple example analysis php file Upload principle in-depth analysis and understanding php file Upload Simple example php file Upload simple example learn how PHP file upload works php increases file upload size limit php settings allow large file upload methods share a php file Upload Class PHP implements file upload code

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.