请问用PHP和MYSQL如何实现图像上传,我是菜鸟 http://cn.php.net/manual/en/features.file-upload.php 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php/*$storeDir = "相对路径,如 ./upload"形式*/class Upload{ var $_allowType; var $_allowSize; var $_storeDir; var $_userFile; function Upload($allowType="jpg|jpeg|gif|bmp",$allowSize,$storeDir,$userFile) { $this->_allowType = $allowType; $this->_allowSize = $allowSize; $this->_storeDir = $storeDir; $this->_userFile = $userFile; } function StartUpload() { if(!is_array($this->_userFile)) { die("参数传递错误,请选择一个文件!"); } if (!empty($this->_userFile['name'])) { if($this->_userFile['size'] > $this->_allowSize) { die("文件太大,允许上传文件的大小为".$this->_allowSize); } $fileName = $this->_userFile['name']; if(!strstr($fileName,".")) { $fileName .=".txt"; $ext = "txt"; } else { $ext = substr(strrchr($fileName,"."),1); if(!preg_match("/$ext/is",$this->_allowType)) { die("您上传的文件类型不正确,充许的文件类型为".$this->_allowType); } } $newFileName = time().rand(1,10000).".".$ext; if(!move_uploaded_file($this->_userFile['tmp_name'],$this->_storeDir."/".$newFileName)) { die("复制文件失败"); } return $newFileName; } }} ?> php正则表达 php能否实现服务器端txt文件转epub文件,word转epub文件,pdf转epub文件 诚聘英才 PHP一个小错误 老师进来帮忙分析下 关于字符串处理 php老是抱的一个错误,自己看不懂,高手帮忙看看,谢谢! 请教高手一个小问 有没有仁兄想一起组个团队来开发?共同发展的? 对于php编辑器的感想,顺便中秋节散分 php+mysql+IIS php投票问题 1。apache 和php结合后,为什么session一直在,不会自动消失?
/*
$storeDir = "相对路径,如 ./upload"形式
*/
class Upload
{
var $_allowType;
var $_allowSize;
var $_storeDir;
var $_userFile;
function Upload($allowType="jpg|jpeg|gif|bmp",$allowSize,$storeDir,$userFile)
{
$this->_allowType = $allowType;
$this->_allowSize = $allowSize;
$this->_storeDir = $storeDir;
$this->_userFile = $userFile;
}
function StartUpload()
{
if(!is_array($this->_userFile))
{
die("参数传递错误,请选择一个文件!");
}
if (!empty($this->_userFile['name']))
{
if($this->_userFile['size'] > $this->_allowSize)
{
die("文件太大,允许上传文件的大小为".$this->_allowSize);
}
$fileName = $this->_userFile['name'];
if(!strstr($fileName,"."))
{
$fileName .=".txt";
$ext = "txt";
}
else
{
$ext = substr(strrchr($fileName,"."),1);
if(!preg_match("/$ext/is",$this->_allowType))
{
die("您上传的文件类型不正确,充许的文件类型为".$this->_allowType);
}
}
$newFileName = time().rand(1,10000).".".$ext;
if(!move_uploaded_file($this->_userFile['tmp_name'],$this->_storeDir."/".$newFileName))
{
die("复制文件失败");
}
return $newFileName;
}
}
}
?>