从phpclasses.org拉了一个现成的类,你看看,不需要另外加.dll,生成缩略图可以自己扩充 <? /*---------------------------------------------------------------------------------- | Class SDImageUploading image uploading | Example: | Copyright ? 2001 SexDev.com! Inc. All rights reserved. | <? | $iu = new SDImageUploading(); | // 'newname' - optional field, leave it | //empty if you want to use original file name | $iu->doUpload('/usr/html/images/',$HTTP_POST_FILES["img"],'newname'); | //return uploaded image name (include server path) or false | | //Also you can print error code (if false result returned) | echo $iu->error | ?> -----------------------------------------------------------------------------------*/ class SDImageUploading { var $disk_path; //disk path where new image will be uploaded var $new_uimage_name; //new image name var $uimage_extension; //new image extension var $uimage; //uploaded image var $error; //error code var $uploaded_file; //succesfully uploaded file name //check image type function function addcheckImgType() { if((strcmp($this->uimage['type'],'image/jpeg')==0)||(strcmp($this->uimage['type'],'image/gif')==0)|| (strcmp($this->uimage['type'],'image/pjpeg')==0)||(strcmp($this->uimage['type'],'image/jpg')==0)||(strcmp($this->uimage['type'],'image/x-png')==0)) { switch($this->uimage['type']){ case 'image/jpg': $this->uimage_extension = '.jpg'; break; case 'image/jpeg': $this->uimage_extension = '.jpg'; break; case 'image/pjpeg': $this->uimage_extension = '.jpg'; break; case 'image/gif': $this->uimage_extension = '.gif'; break; case 'image/x-png': $this->uimage_extension = '.png'; break; } return true; }else{ $this->error .= '<br>Invalid image type '.$this->uimage['type']; return false; } } //start upload and check image type function doUpload($new_disk_path,$new_uimage,$new_uimage_name='') { $this->disk_path = $new_disk_path; $this->uimage = $new_uimage; $this->uploaded_file = ''; if($new_uimage_name != ''){ $this->new_uimage_name = $new_uimage_name; }else{ $this->new_uimage_name = $this->uimage_name; } $this->addcheckImgType(); if($this->uimage_extension){ $uimageFinal = $this->disk_path.$this->new_uimage_name.$this->uimage_extension; if(copy($this->uimage['tmp_name'], $uimageFinal)){ $this->uploaded_file = $this->new_uimage_name.$this->uimage_extension; return $uimageFinal; }else{ $this->error .= '<br>Cannot copy image to '.$uimageFinal.'. Check chmod and server path '.$this->disk_path; return false; } }else{ $this->error .= '<br>Can not get image extension '.$this->uimage_extension; return false; } } } ?>
<?
/*----------------------------------------------------------------------------------
| Class SDImageUploading image uploading
| Example:
| Copyright ? 2001 SexDev.com! Inc. All rights reserved.
| <?
| $iu = new SDImageUploading();
| // 'newname' - optional field, leave it
| //empty if you want to use original file name
| $iu->doUpload('/usr/html/images/',$HTTP_POST_FILES["img"],'newname');
| //return uploaded image name (include server path) or false
|
| //Also you can print error code (if false result returned)
| echo $iu->error
| ?>
-----------------------------------------------------------------------------------*/
class SDImageUploading {
var $disk_path; //disk path where new image will be uploaded
var $new_uimage_name; //new image name
var $uimage_extension; //new image extension
var $uimage; //uploaded image
var $error; //error code
var $uploaded_file; //succesfully uploaded file name //check image type function
function addcheckImgType()
{
if((strcmp($this->uimage['type'],'image/jpeg')==0)||(strcmp($this->uimage['type'],'image/gif')==0)|| (strcmp($this->uimage['type'],'image/pjpeg')==0)||(strcmp($this->uimage['type'],'image/jpg')==0)||(strcmp($this->uimage['type'],'image/x-png')==0))
{
switch($this->uimage['type']){
case 'image/jpg':
$this->uimage_extension = '.jpg';
break;
case 'image/jpeg':
$this->uimage_extension = '.jpg';
break;
case 'image/pjpeg':
$this->uimage_extension = '.jpg';
break;
case 'image/gif':
$this->uimage_extension = '.gif';
break;
case 'image/x-png':
$this->uimage_extension = '.png';
break;
}
return true;
}else{
$this->error .= '<br>Invalid image type '.$this->uimage['type'];
return false;
}
} //start upload and check image type
function doUpload($new_disk_path,$new_uimage,$new_uimage_name='')
{
$this->disk_path = $new_disk_path;
$this->uimage = $new_uimage;
$this->uploaded_file = '';
if($new_uimage_name != ''){
$this->new_uimage_name = $new_uimage_name;
}else{
$this->new_uimage_name = $this->uimage_name;
} $this->addcheckImgType(); if($this->uimage_extension){
$uimageFinal = $this->disk_path.$this->new_uimage_name.$this->uimage_extension;
if(copy($this->uimage['tmp_name'], $uimageFinal)){
$this->uploaded_file = $this->new_uimage_name.$this->uimage_extension;
return $uimageFinal;
}else{
$this->error .= '<br>Cannot copy image to '.$uimageFinal.'. Check chmod and server path '.$this->disk_path;
return false;
}
}else{
$this->error .= '<br>Can not get image extension '.$this->uimage_extension;
return false;
}
}
}
?>
PHPixPhotoAlbum :http://phpix.org上下载这个工具
不过要注意,它有一个漏洞可以让浏览器遍历你的目录---通过发送$mode=album&album=_some_dir_variable实现
修补方法:---官方的还没有出,或许我不知道
1:建立专门的用户,专门目录;
2:改变其中的一个函数;
3:终极方法,代码中限制,不允许有以下划线出现的变量---除了用户名。这也是我对我的所有的php文件做的处理^-^
呵呵
通过imagesize即可得到图像尺寸