PHP upload file code, suitable for beginners only, the code is simple and easy to understand.
PHP is very important in PHP. It is one of the common functions. For example, we want to upload and download files, or to deal with uploaded pictures, all of which need to be used to PHP uploading technology. A simple upload file code can be done, the following is a simple PHP novice file upload code, only suitable for beginners, the code is simple and easy to understand, of course, PHP upload technology far away, we can find a lot of free PHP uploading files on the Internet, the function is quite perfect, and these only need one One kind of file can be realized, if you are a novice, you can study the code for uploading files:
PHP code
[code].Lt; PHP
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Parameter Description:
$max_file_size: setting uploaded files big Small
$destination_folder: upload file save path
$imageview: whether to generate thumbnails (1 for generation, other is not generated)
$imageviewsize: the proportion of thumbnails (the default is 1/2, the size of 50%)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ / / / upload file type
$FileTypes=array (
'image/jpg',
'image/jpeg',
'image/png',
>); / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Ion_folder='upfile/'; / / / / upload file save path
$imageview=1; / / / / / / / / / / / / / / / / / / / / / / / / / / / / thumbnail ratio;
$imageviewsize=1/2; / / / thumbnail ratio;
.Gt;
.Lt; html.gt;
Nt-Type.quot; content=.quot; text/html; charset=gb2312.quot; /.gt;
.Lt; title.gt; title.gt; /title.gt; /title.gt;
.Lt; /head.gt;
.Lt; body.gt;
.Lt; form enctype=.quot; multipart/form-data.quot. T; input type=.quot; submit.quot; name=.quot; submit.quot; value=.quot; start to upload.Quot; /.gt;
.Lt; /form.gt; {] {/ >]) 'files do not exist';
exit;
}
$upfile=$_FILES.#91;'file'.#93;
if ($max_file_size.Lt; $upfile.#91;'size'.#93; > > > > > {} / >) / > echo 'file type is not conformed';
exit;
}
if (! File_exists ($destination_folder)) {
MKDIR ($destination_folder);
} / / / defined uploaded file variable / >; Agesize ($filename);
$pinfo=pathinfo ($upfile.#91;'name'.#93;);
/ / print_r ($pinfo);
$file_type=$pinfo.#91;'extension'.#93; STS ($destination)) {
echo.Quot;.Lt; br /.gt; file already exists, no upload success!.quot;
exit;
> > {/ >} / > {} / > {} O ($destination);
/ / / / / / / / / / >
if (! (@getimagesize ($destination))) {
echo 'prohibit illegal operation';
/ / / / / / > unlink / >} / >};
/ / / / print_r ($image_size);
/ / print_r ($pinfo);
echo 'file has been uploaded successfully, the file name is'.$pinof.#91; basename.#93;..quot;.Lt.
echo'.lt; br /.gt; file size'.filesize ($destination).'bytes';
echo'.lt; br echo; Echo 'picture thumbnail.Lt; br /.gt;
echo.Quot;.Lt; img src='.quot;.$destination..Quot; width=.quot;}; [/code] > >.Gt;
.Lt; /body.gt;
.Lt; /html.gt; [/code]