Home > Backend Development > PHP Tutorial > A simple PHP image upload class with image display code_PHP tutorial

A simple PHP image upload class with image display code_PHP tutorial

WBOY
Release: 2016-07-20 11:09:07
Original
932 people have browsed it

This is a simple PHP image upload class with image display code. It can be said to be the simplest upload class to upload files. You can set the height and width of the image to be displayed, the file size, etc.

This is a simple php tutorial image upload class with image display code. It should be said to be the simplest upload class to upload files. You can set the height and width of the image to be displayed, the file size, etc.

uploadimg.class.php file

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; //The width of the image to be displayed
var $image_h=350; //The width of the image to be displayed High
var $upload_file_size;
var $upload_must_size= 50000; //Allow the size of uploaded files, set it yourself
function upload_file()
{
$this->upload_name = $_files ["file"]["name"]; //Get the name of the uploaded file
$this->upload_filetype = $_files["file"]["type"];
$this->upload_server_name = date("y_m_dh_i_s").$this->upload_name;
$this->upload_tmp_address = $_files["file"]["tmp_name"]; //Get the temporary address
$this-> file_type = array("image/gif","image/pjpeg"); //Types of files allowed to be uploaded
$this->upload_file_size = $_files["file"]["size"]; //Upload The size of the file
if(in_array($this->upload_filetype,$this->file_type))
{ if($this->upload_file_size < $this->upload_must_size)
{
echo("Upload successful, thank you for your support");
$this->file_server_address = "d:www.bkjia.comupload/".$this->upload_server_name;
move_uploaded_file($this- >upload_tmp_address,$this->file_server_address);//Move out of the temp directory
echo("file_server_address width=$this->image_w height=$this-> image_h/>"); //Display image


}
else
{
echo("File size is too large");
}
}
else
{
echo("This file type is not supported, please select again");
}

}

}


html upload code






Call method
upload.php

inlcude('uploadimg.class.php');

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444832.htmlTechArticleThis is a simple PHP image upload class with image display code. It should be said that it is the easiest way to upload files. Class, you can set the height and width of the image to be displayed, the file size, etc. This is...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template