小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

php 文件上傳函數(shù)(超詳細(xì))

 163九九 2016-04-13

最新php 文件上傳函數(shù)(超詳細(xì))

以下是三零網(wǎng)為大家整理的最新php 文件上傳函數(shù)(超詳細(xì))的文章,希望大家能夠喜歡!

/**
 * 文件上傳
 *
 * 返回的數(shù)組索引
 * mime_type 文件類型
 * size      文件大小(單位KB)
 * file_path 文件路徑
 * width     寬度
 * height    高度
 * 可選值(僅在上傳文件是圖片且系統(tǒng)開啟縮略圖時(shí)起作用)
 * thum_file   縮略圖的路徑
 * thum_width  縮略圖寬度
 * thum_height 縮略圖高度
 * thum_size   縮略圖大小(單位KB)
 *
 * @param string $fileName 文件名
 * @param string $errorNum 錯誤碼:$_FILES['error']
 * @param string $tmpFile 上傳后的臨時(shí)文件
 * @param string $fileSize 文件大小 KB
 * @param array $type 允許上傳的文件類型
 * @param boolean $isIcon 是否為上傳頭像
 * @param boolean $is_thumbnail 是否生成縮略圖
 * @return array 文件數(shù)據(jù) 索引
 *
 */
function upload($fileName, $errorNum, $tmpFile, $fileSize, $type, $isIcon = false, $is_thumbnail = true) {
 if ($errorNum == 1) {
  return '100'; //文件大小超過系統(tǒng)限制
 } elseif ($errorNum > 1) {
  return '101'; //上傳文件失敗
 }
 $extension = getFileSuffix($fileName);
 if (!in_array($extension, $type)) {
  return '102'; //錯誤的文件類型
 }
 if ($fileSize > Option::UPLOADFILE_MAXSIZE) {
  return '103'; //文件大小超出emlog的限制
 }
 $file_info = array();
 $file_info['file_name'] = $fileName;
 $file_info['mime_type'] = get_mimetype($extension);
 $file_info['size'] = $fileSize;
 $file_info['width'] = 0;
 $file_info['height'] = 0;
 $uppath = Option::UPLOADFILE_PATH . gmdate('Ym') . '/';
 $fname = substr(md5($fileName), 0, 4) . time() . '.' . $extension;
 $attachpath = $uppath . $fname;
 $file_info['file_path'] = $attachpath;
 if (!is_dir(Option::UPLOADFILE_PATH)) {
  @umask(0);
  $ret = @mkdir(Option::UPLOADFILE_PATH, 0777);
  if ($ret === false) {
   return '104'; //創(chuàng)建文件上傳目錄失敗
  }
 }
 if (!is_dir($uppath)) {
  @umask(0);
  $ret = @mkdir($uppath, 0777);
  if ($ret === false) {
   return '105'; //上傳失敗。文件上傳目錄(content/uploadfile)不可寫
  }
 }
 doAction('attach_upload', $tmpFile);

 // 生成縮略圖
 $thum = $uppath . 'thum-' . $fname;
 if ($is_thumbnail) {
  if ($isIcon && resizeImage($tmpFile, $thum, Option::ICON_MAX_W, Option::ICON_MAX_H)) {
   $file_info['thum_file'] = $thum;
   $file_info['thum_size'] = filesize($thum);
   $size = getimagesize($thum);
   if ($size) {
    $file_info['thum_width'] = $size[0];
    $file_info['thum_height'] = $size[1];
   }
   resizeImage($tmpFile, $uppath . 'thum52-' . $fname, 52, 52);
  } elseif (resizeImage($tmpFile, $thum, Option::IMG_MAX_W, Option::IMG_MAX_H)) {
   $file_info['thum_file'] = $thum;
   $file_info['thum_size'] = filesize($thum);
   $size = getimagesize($thum);
   if ($size) {
    $file_info['thum_width'] = $size[0];
    $file_info['thum_height'] = $size[1];
   }
  }
 }

 if (@is_uploaded_file($tmpFile)) {
  if (@!move_uploaded_file($tmpFile, $attachpath)) {
   @unlink($tmpFile);
   return '105'; //上傳失敗。文件上傳目錄(content/uploadfile)不可寫
  }
  @chmod($attachpath, 0777);
 }
 
 // 如果附件是圖片需要提取寬高
 if (in_array($file_info['mime_type'], array('image/jpeg', 'image/png', 'image/gif', 'image/bmp'))) {
  $size = getimagesize($file_info['file_path']);
  if ($size) {
   $file_info['width'] = $size[0];
   $file_info['height'] = $size[1];
  }
 }
 return $file_info;
}

 


延伸閱讀:
·php文件上傳函數(shù)
·php處理 單文件、多文件上傳
·一個(gè)簡單的PHP文件上傳方法
·php文件上傳中值得注意的幾點(diǎn)
·php文件上傳相關(guān)配置教程
·php大文件上傳,fastcgi大文件上傳,出現(xiàn)中斷或者上傳失敗的解決方法
·PHP程序中文件上傳的安全問題
·PHP 文件上傳程序簡單例子
·php多文件簡單上傳示例
·PHP多文件上傳個(gè)人理解總結(jié)
·PHP 另一個(gè)文件上傳類
·用PHP實(shí)現(xiàn)文件上傳二法
·php 文件上傳類
·用PHP實(shí)現(xiàn)文件上傳
·php上傳類型限制,php文件上傳實(shí)例

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多