Php automatically creates folders and uploads files
-
Session_start ();
- If ($ _ SESSION ['Company'] = '')
- {
- // Exit ();
- }
- ?>
- $ 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; // size limit of uploaded files, in bytes
-
$ 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 image (1 is generated, others are not generated );
- $ Imgpreviewsize = 1/2; // Thumbnail ratio
- If ($ _ SERVER ['request _ method'] = 'post ')
- {
- If (! Is_uploaded_file ($ _ FILES ["Pic"] [tmp_name])
- // Whether a file exists
- {
- Echo "the file does not exist! ";
- Exit;
- }
- $ File = $ _ FILES ["Pic"];
- If ($ max_file_size <$ file ["size"])
- // Check the file size
- {
- Echo "the file is too large! ";
- Exit;
- }
- If (! In_array ($ file ["type"], $ uptypes ))
- // Check the file type
- {
- Echo "only Image files or Flash files can be uploaded! ";
- 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 "the file with the same name already exists! ";
- Exit;
- }
- If (! Move_uploaded_file ($ filename, $ destination ))
- {
- Echo "an error occurred while uploading files! ";
- 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 ['posit'];
- $ 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 later
- $ Infor-> IssueTime = time ();
- $ Infor-> ViewNum = 0;
- $ Infor-> State = 1; // It is not fixed now and will be modified later
- $ Infor-> Top = 0;
- $ Infor-> Recommend = 0;
- $ Infor-> BookMember-> ID = 0;
- $ Infor-> BookTime = 0;
- $ Infor-> BookRemark = 0;
- $ BLL_Trade-> CreateInfor ($ Infor );
- Echo 'Publish information successful! ';
- }
- Catch (Exception $ Err ){
- Echo $ Err-> getMessage ();
- }
- ?>
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 |