PHP File Upload Code

Source: Internet
Author: User
Tags explode php file upload
The code is as follows Copy Code

<form name= "Form1" enctype= "Multipart/form-data" method= "POST" action= "" >
<label for= "Filefield" ></label>
<input type= "File" Name= "Filefield" id= "Filefield" >
<input type= "Submit" name= "button" id= "button" value= "Upload file" >
</form>
<?php
/*
* $NAME; Upload file name
* $size: Upload file size
* $PATH; File Original path
* $newpath: Set a new path
* $not: An array of file types that are prohibited from uploading
* $notsize: Limit the value of the file size
* $move: Upload file source
*
*/

Class FileUpload {
Public $name;
Public $size;
public $path;
Public $newpath;
Public $not = Array ();
Public $notsize;
Public $move;
Public $allfile = Array ();
function __construct ($name, $size, $path, $newpath, $not, $notsize) {
$this->name = $name;
$this->size = $size/1048576;
$this->path = $path;
$this->newpath = $newpath;
$this->not = Explode (', ', $not);
$this->notsize = $notsize;
$this->upload ();
}
/*
* Upload Program
* First determine whether the directory exists
* Determine file type and size
*/
function upload () {
if (!file_exists ($this->newpath)) {
echo "<script>alert (' This directory does not exist! ') </script>;
Return
}else{
$arr = Explode ('. ', $this->name);
if (In_array ($arr [1], $this->not)) {
echo "<script>alert (' This type of file is forbidden to upload! ') </script> ";
Return
}else if ($this->name = = ") {
echo "<script>alert (' Please select uploaded file! ') </script> ";
Return
}else if ($this->size> $this->notsize) {
echo "<script>alert (' upload file exceeds specified size! ') </script> ";
Return
}else if (file_exists ("$this->newpath".) $this->name ")) {
echo "<script>alert (' This file already exists! ') </script> ";
Return
}
else{
$this->move = Move_uploaded_file ($this->path, $this->newpath. $this->name);
$this->move ();
}
}
}
/*
* To determine whether the file upload success
*/
function Move () {
if ($this->move) {
echo "<script>alert (' File Upload success! ') </script>;
Return
}else{
echo "<script>alert (' upload failed! ') </script>;
Return
}
}
}


$fu = new FileUpload ($array [name], $array [size], $array [Tmp_name], './www.111cn.net/', ' Exe,rar ', 5);

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.