php 產生自動建立檔案夾並上傳檔案的範例程式碼_PHP教程

來源:互聯網
上載者:User
複製代碼 代碼如下:
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; //上傳檔案大小限制, 單位BYTE


$addtime=date("Ymd",time());
$testdir="./".$addtime."/";
if(file_exists($testdir)):
else:
mkdir($testdir,0777);
endif;

$destination_folder=$addtime."/"; //上傳檔案路徑
$imgpreview=1; //是否產生預覽圖(1為產生,其他為不產生);
$imgpreviewsize=1/2; //縮圖比例

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["Pic"][tmp_name]))
//是否存在檔案
{
echo "檔案不存在!";
exit;
}

$file = $_FILES["Pic"];
if($max_file_size < $file["size"])
//檢查檔案大小
{
echo "檔案太大!";
exit;
}

if(!in_array($file["type"], $uptypes))
//檢查檔案類型
{
echo "只能上傳影像檔或Flash!";
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 "同名檔案已經存在了!";
exit;
}

if(!move_uploaded_file ($filename, $destination))
{
echo "上傳檔案出錯!";
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;//日後修改
$Infor->IssueTime = time();
$Infor->ViewNum = 0;
$Infor->State = 1;//現在未定,日後修改
$Infor->Top = 0;
$Infor->Recommend = 0;
$Infor->BookMember->ID = 0;
$Infor->BookTime = 0;
$Infor->BookRemark = 0;
$BLL_Trade->CreateInfor($Infor);
echo '發布資訊成功!';
}
catch (Exception $Err){
echo $Err->getMessage();
}
?>

http://www.bkjia.com/PHPjc/736787.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/736787.htmlTechArticle複製代碼 代碼如下: ? session_start(); if($_SESSION['Company']=='') { //exit(); } ??php //上傳圖片 $uptypes=array('image/jpg','image/jpeg','image/png','image/pjpeg','ima...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.