PHP generates sample code that automatically creates folders and uploads files

Source: Internet
Author: User
Tags file size mkdir

  This article is mainly on the PHP generated automatically create folders and upload files of the sample code is introduced, need friends can come to the reference, I hope to help you.

    Code is as follows: Session_Start (); if ($_session[' company ']== ') { //exit ()}? ><?php//Upload pictures   $uptypes =array (' image/jpg ', ' image/jpeg ', ' Image/png ', ' image/pjpeg ', ' image/gif ', ' image/bmp ', ' application/x-shockwave-flash ', ' image/x-png ');  $max _ file_size=5000000;    //upload file size limit, Unit byte       $addtime =date ("Ymd", Time ());         $testdir = "./". $addtime. " /";      if (file_exists $testdir):      Else:      mkdir ($testdir, 0777);      endif;      $destination _folder= $addtime. " /"; Upload file path $imgpreview = 1;    //whether to generate a preview diagram (1 is generated, others are not generated); $imgpreviewsize =1/2;  //thumbnail proportions   if ($_server[' request_method '] = = ' POST ') {if (!is_uploaded_file ($_files["Pic"][tmp_name)) Is there a file {  echo "<font color= ' Red ' > file does not exist! </font> "; Exit }   $file = $_files["Pic"]; if ($max _file_size < $file ["size"])//Check file size {echo <font color= ' red ' > file is too big! </font> "; Exit   &NBSP}   if (!in_array ($file [type], $uptypes))//Check file type {echo "<font color= ' red ' > can only upload image files or flash! </font> "; exit; }   if (!file_exists ($destination _folder))  mkdir ($destination _folder);   $filename = $file ["Tmp_name"]; $image _size = getimagesize ($filename);  $pinfo =pathinfo ($file ["name"]); $ftype = $pinfo [extension]; $PicName = Time (). "." $ftype; $destination = $destination _folder. $PicName;   if (file_exists ($destination) && $overwrite!= True)   {      echo "<font color= ' red ' > file with the same name already exists! </a> ";       exit;   if (!move_uploaded_file ($filename, $destination)) {      echo ' <font color= ' red ' > Error uploading file! </a> ";       exit; }   $pinfo =pathinfo ($destination); $fname = $pinfo [basename]; ><?   $path = dirname (__file__); Require_once ($path. ' /.. /.. /module/factory.php ');   $Factory = new Factory (); $BLL _trade = $Factory->factorytrade (); try {$Infor = new infor (); $Infor->title = $_post[' Title ']; $Infor->deposit = $_post[' deposit ']; $Infor->hire = $_post[' Hire ']; $Infor->location = $_post[' Location ']; $Infor->pic = $destination; $Infor->intro = $_post[' Intro ']; if ($_session[' memberid '] = = ') {  $Infor->member->id= ';} else {$Infor->member->id = $_session[' MemberID '];} if ($_post[' goodsbarcode '] = = ') {  $Infor->goods- >barcode = 0; }else {$Infor->goods->barcode = $_post[' Goodsbarcode ']; $Infor->class->id = 0;//Modify $Infor later-> Issuetime = time (); $Infor->viewnum = 0; $Infor->state = 1;//is now undecided, later modified $Infor->top = 0; $Infor->recommend = 0; $Infor->bookmember->id = 0; $Infor->booktime = 0; $Infor->bookremark = 0; $BLL _trade->createinfor ($Infor); Echo ' Publish the information successfully! '; The catch (Exception $Err) { echo $Err->getmessage ();}?>

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.