当前位置:Gxlcms > PHP教程 > PHP图片上传类带图片显示_PHP教程

PHP图片上传类带图片显示_PHP教程

时间:2021-07-01 10:21:17 帮助过:21人阅读

这是一个PHP的文件上传类带图片显示的.其实做成函数就可以了.不过还是做成类好玩一点.~~~~
本来应该用JS来验证上传文件类型的.但懒得做了.





无标题文档





Class upload
{
var $upload_name;
var $upload_tmp_address;
var $upload_server_name;
var $upload_filetype ;
var $file_type;
var $file_server_address;
var $image_w=900; //要显示图片的宽
var $image_h=350; //要显示图片的高
var $upload_file_size;
var $upload_must_size= 50000; //允许上传文件的大小,自己设置
function upload_file()
{
https://www.gxlcms.com/$this->upload_name = $_FILES["file"]["name"]; //取得上传文件名
https://www.gxlcms.com/$this->upload_filetype = $_FILES["file"]["type"];
https://www.gxlcms.com/$this->upload_server_name = date("Y_m_dH_i_s").https://www.gxlcms.com/$this->upload_name;
https://www.gxlcms.com/$this->upload_tmp_address = $_FILES["file"]["tmp_name"]; //取得临时地址
https://www.gxlcms.com/$this->file_type = array("image/gif","image/pjpeg"); //允许上传文件的类型
https://www.gxlcms.com/$this->upload_file_size = $_FILES["file"]["size"]; //上传文件的大小
if(in_array(https://www.gxlcms.com/$this->upload_filetype,https://www.gxlcms.com/$this->file_type))
{ if(https://www.gxlcms.com/$this->upload_file_size < https://www.gxlcms.com/$this->upload_must_size)
{
echo("上传成功,谢谢支持");
https://www.gxlcms.com/$this->file_server_address = "D:\usr\www\html\upload/".https://www.gxlcms.com/$this->upload_server_name;
move_uploaded_file(https://www.gxlcms.com/$this->upload_tmp_address,https://www.gxlcms.com/$this->file_server_address);//从TEMP目录移出
echo("file_server_address width=https://www.gxlcms.com/$this->image_w height=https://www.gxlcms.com/$this->image_h/>"); //显示图片


}
else
{
echo("文件容量太大");
}
}
else
{
echo("不支持此文件类型,请重新选择");
}

}

}
$dd = new upload;
$dd->upload_file();
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317215.htmlTechArticle这是一个PHP的文件上传类带图片显示的.其实做成函数就可以了.不过还是做成类好玩一点.~~~~ 本来应该用JS来验证上传文件类型的.但懒得做了...

人气教程排行