php 上傳類(自家用)

來源:互聯網
上載者:User

簡介:這是php 上傳類(自家用)的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=324387' scrolling='no'>
<?php
/**
* File up load class
* @version 1.0.0 (Thu Aug 18 01:32:39 CST 2005)
* @author sanshi
*/
class upLoad
{
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:00:18 CST 2005
* @param string $info 檔案內容
* @param string $fileName 產生的檔案名稱
* @return boolean 建立成功返回true
* @deprecated
* 建立html檔案
*/
function createHtml( $info ,$fileName )
{
}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:03:09 CST 2005
* @return void
* @deprecated
* 建構函式
*/
function downLoad()
{}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:03:55 CST 2005
* @param string $fileField 在表單中的欄位名
* @param string $length 限制的長度
* @return boolean 成功返回true
* @deprecated
* 功能實現函數
*/
function init($fileField,$length='')
{
$files = $_FILES[$fileField];
//使用者名稱需要改動,根據自己的實際情況做改動
$userName = 'sanshi';
$fileName = $files['name'];
$fileType = $files['type'];
$fileTemp = $files['tmp_name'];
$fileSize = empty( $length ) ? ($files['size'] 10) : $length;
$fileError= $files['error'];//這塊也許php4中沒有
//改為
//if( $this->_isType( $fileName ) || $this->_isBig( $length ) )
if( !$this->_isType( $fileName ) || $this->_isBig( $length ) || $fileError != 0 )
{
//print_r ($files);
return false;
}else{
$path = $this->_createDir( $userName );//取得路徑
$createFileName = $userName . "_" . time();//設定當前檔案名稱
$createFileType = $this->getFileType($fileName);//設定檔案類別
return @move_uploaded_file($fileTemp,$path.$createFileName.'.'.$createFileType) ? true : false;
}
}

/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:07:43 CST 2005
* @param int $length 上傳限制的大小
* @return boolean 超過返回true
* @deprecated
* 判斷是否超過預定大小
*/
function _isBig($length)
{
$bigest = '';
return $big > $bigest ? true : false;
}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:08:55 CST 2005
* @param string $fileName 檔案名稱
* @return string $fileType 檔案尾碼
* @deprecated
* 取得檔案尾碼(只取得檔案的最後一個尾碼名)
*/
function getFileType($fileName)
{
return end(explode('.',$fileName));
}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:10:41 CST 2005
* @param string $fileName 檔案名稱
* @param boolean $method 是否檢查多個尾碼預設false
* @param int $postFix 尾碼個數預設為2
* @return boolean 存在返回true
* @deprecated
* 檢查檔案的尾碼是否在類別數組中,類別數組自己設定
* 如果$method設定為true則檢查檔案有幾個尾碼
*/
function _isType($fileName,$method='false',$postFix=2)
{
//設定類別數組
$type = array('jpeg',
'gif',
'bmp',
'exe');
$fileName = strtolower( $fileName );
$fileTypeArray = explode( '.',$fileName );
$fileType = end( $fileTypeArray );
//判斷是否有一個檔案有多個尾碼
if($method)
{
if( count( $fileTypeArray ) > (is_int($postFix) ? $postFix : 2) )
{
return false;
}
}
return in_array($fileType,$type);
}

/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:17:19 CST 2005
* @param string $userName
* @return string $path
* @deprecated
* 建立目錄 目錄格式 年/月/日/使用者名稱/
* 許可權為755
*/
function _createDir($userName)
{
$root = '';
$pathSign = DIRECTORY_SEPARATOR;
$y = date('Y').$pathSign;
$m = date('m').$pathSign;
$d = date('d').$pathSign;
$path = $root . $y . $m . $d . $userName;
$dirArray = explode( $pathSign,$path);
$tempDir='';
foreach ( $dirArray as $dir)
{
$tempDir.= $dir.$pathSign;
$isFile = file_exists( $tempDir );
clearstatcache();
if( ! $isFile && !is_dir( $tempDir ) )
{
@mkdir($tempDir,0755);
}
}
return $path . $pathSign;
}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:19:32 CST 2005
* @param  string $dirName 目錄名
* @return   boolean 可以操作返回true
* @deprecated
* 判斷操作是否在上傳目錄
*/
function _isDel($dirName)
{
//注意upLoadDir,一定要與真正使用目錄相對應
$upLoadDir = '';
$upLoadDir = preg_replace('/\\//','\/',$upLoadDir);
$format = "/^{$upLoadDir}/";
return preg_match( $format,$dirName );
}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:25:58 CST 2005
* @param string $fileName 檔案名稱
* @return boolean 刪除檔案成功返回true
* @deprecated
* 刪除檔案
*/
function delFile( $fileName )
{
$cur_dir = dirname(trim($fileName));
if( $this->_isDel( $cur_dir ) )
{
return @unlink( $fileName ) ? true : false;
}else{
return false;
}
}
/**
*
* @author sanshi
* @version 1.0.0 Thu Aug 18 01:27:43 CST 2005
* @param string $dieName 目錄名
* @return boolean 刪除成功返回true
* @deprecated
* 刪除目錄 目錄下如果有檔案不能刪除
*/
function delDir( $dirName )
{
if( $this->_isDel($dirName) && is_dir( $dirName ) )
{
return @rmdir( $dirName ) ? true : false;
}else{
return false;
}
}

}
?>
<?php
//使用
/*
include 'upLoad.class.php';
$up = new upLoad();
if($up->init("file"))
{
echo 'success';
}else{
echo 'failure';
}
*/
?>

“php 上傳類(自家用)”的更多相關文章 》

愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具

http://biancheng.dnbcw.info/php/324387.html pageNo:15

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.