Heim  >  Artikel  >  Backend-Entwicklung  >  php自动创建文件夹并上传文件

php自动创建文件夹并上传文件

WBOY
WBOYOriginal
2016-07-25 08:53:581344Durchsuche
  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; //上传文件大小限制, 单位BYTE
  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."/"; //上传文件路径
  16. $imgpreview=1; //是否生成预览图(1为生成,其他为不生成);
  17. $imgpreviewsize=1/2; //缩略图比例
  18. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  19. {
  20. if (!is_uploaded_file($_FILES["Pic"][tmp_name]))
  21. //是否存在文件
  22. {
  23. echo "文件不存在!";
  24. exit;
  25. }
  26. $file = $_FILES["Pic"];
  27. if($max_file_size //检查文件大小
  28. {
  29. echo "文件太大!";
  30. exit;
  31. }
  32. if(!in_array($file["type"], $uptypes))
  33. //检查文件类型
  34. {
  35. echo "只能上传图像文件或Flash!";
  36. exit;
  37. }
  38. if(!file_exists($destination_folder))
  39. mkdir($destination_folder);
  40. $filename=$file["tmp_name"];
  41. $image_size = getimagesize($filename);
  42. $pinfo=pathinfo($file["name"]);
  43. $ftype=$pinfo[extension];
  44. $PicName = time().".".$ftype;
  45. $destination = $destination_folder.$PicName;
  46. if (file_exists($destination) && $overwrite != true)
  47. {
  48. echo "同名文件已经存在了!";
  49. exit;
  50. }
  51. if(!move_uploaded_file ($filename, $destination))
  52. {
  53. echo "上传文件出错!";
  54. exit;
  55. }
  56. $pinfo=pathinfo($destination);
  57. $fname=$pinfo[basename];
  58. }
  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['Deposit'];
  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;//日后修改
  81. $Infor->IssueTime = time();
  82. $Infor->ViewNum = 0;
  83. $Infor->State = 1;//现在未定,日后修改
  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 '发布信息成功!';
  91. }
  92. catch (Exception $Err){
  93. echo $Err->getMessage();
  94. }
  95. ?>
复制代码

PHP文件上传功能代码实例 PHP文件上传大小设置方法 php文件上传代码大全(实例分享) php文件上传综合实例分享 php 文件上传(普通上传与异步上传)的例子 php 文件上传的实例解析 php 文件上传实例剖析 php单文件上传的实例分析 php多文件上传的简单示例分析 php文件上传原理深入分析与理解 php 文件上传简单示例 php 文件上传简单实例 了解PHP文件上传的原理 PHP增加文件上传大小的限制 php设置允许大文件上传的方法 分享一个PHP文件上传类 php实现文件上传的代码



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn