PHP picture upload class with picture Display _php Foundation

Source: Internet
Author: User
Tags file upload php file upload
This is a php file upload class with pictures displayed. Actually make a function on it. But it's a little bit more fun. ~ ~ ~ ~ ~ ~ ~ ~ ~
You should have used JS to verify the type of upload file. But too lazy to do it.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<body>
<form id= "Form1" name= "Upload" enctype= "Multipart/form-data" method= "post" action= "upload.php" >
<input type= "hidden" name= "max_file_size"/>
<input type= "File" name= "file"/>
<input type= "Submit" name= "Submission" value= "submitted"/>
</form>
</body>
<?php
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; To display the width of a picture
var $image _h=350; To display the height of the picture
var $upload _file_size;
var $upload _must_size= 50000; Allow file size to be uploaded, set yourself
function Upload_file ()
{
$this->upload_name = $_files["File" ["Name"]; Get upload file name
$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 a temporary address
$this->file_type = Array ("Image/gif", "image/pjpeg"); Types of files allowed to upload
$this->upload_file_size = $_files["File" ["Size"]; Size of uploaded file
if (In_array ($this->upload_filetype, $this->file_type))
{if ($this->upload_file_size < $this->upload_must_size)
{
Echo ("Upload success, thank you for support");
$this->file_server_address = "d:\usr\www\html\upload/". $this->upload_server_name;
Move_uploaded_file ($this->upload_tmp_address, $this->file_server_address);//move out from temp directory
Echo ("file_server_address width= $this->image_w height= $this->image_h/>"); Show pictures


}
Else
{
Echo ("File capacity is too large");
}
}
Else
{
Echo ("Do not support this file type, please select Again");
}

}

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.