Two php file upload program

Source: Internet
Author: User
Tags file upload php file upload rand

$sort = 12;
$f _type=strtolower ("swf,jpg,rar,zip,7z,iso,gif");//Set the file types that can be uploaded
$file _size_max=200*1024*1024;//Limit the maximum size of a single file upload
$overwrite = 0;//is allowed to overwrite the same file, 1: Allowed, 0: not allowed
$f _input= "Files";/set up to upload the domain name
foreach ($_files[$f _input]["error"] as $key => $error) {
$up _error= "No";
if ($error = = UPLOAD_ERR_OK) {
$f _name=$_files[$f _input][' name ' [$key];//get upload source filename

$uploadfile = $uploaddir. Strtolower (basename ($f _name));

$tmp _type=substr (STRRCHR ($f _name, "."), 1)//Get file name extension
$tmp _type=strtolower ($tmp _type);
if (!stristr ($f _type, $tmp _type)) {
echo "<script>alert (' Sorry, can't upload". $tmp _type. " Format file, ". $f _name." File upload failed! ') </script> ";
$up _error= "yes";
}

if ($_files[$f _input][' size '] [$key]> $file _size_max) {

echo "<script>alert (' Sorry, you uploaded the file". $f _name. "Capacity is". Round ($_files[$f _input]
[' Size '] [$key]/1024). " KB, greater than the specified ". ($file _size_max/1024). " KB, upload failed! ') </script> ";
$up _error= "yes";
}

if (file_exists ($uploadfile) &&! $overwrite) {
echo "<script>alert (' Sorry, file". $f _name. "Already exist, upload failed! ') </script> ";
$up _error= "yes";
}
$string = ' abcdefghijklmnopgrstuvwxyz0123456789 ';
$rand = ';
For ($x =0 $x <12; $x + +)
$rand. = substr ($string, Mt_rand (0,strlen ($string)-1), 1);
$t =date ("Ymdhis"). substr ($gettime [0],2,6). $rand;
$attdir = "./file/";
if (!is_dir ($attdir))
{mkdir ($attdir);}
$uploadfile = $attdir. $t. ". $tmp _type;
if ($up _error!= "yes") and (move_uploaded_file $_files[$f _input][' tmp_name ')

[$key], $uploadfile))) {


$_msg=$_msg. $f _name. ' Upload success ';


}
else{
$_msg=$_msg. $f _name. ' Upload failed ';
}
}

}
echo "<script>window.parent.finish" ("$_msg."); </script> ";
?>

Second File Upload code

<?php
$destination _path = '.. /.. /upfile/jianjulogo/';//getcwd (). Directory_separator;

$result = 0;

$target _path = $destination _path. basename ($_files[' myfile '] [' name ']);

if (@move_uploaded_file ($_files[' myfile '] [' tmp_name '], $target _path)) {
$result = 1;
}
echo $target _path;
Sleep (1);


?>
<script language= "Web Effects" type= "Text/javascript" >window.top.window.stopupload (<?php echo $result; <?= $target _path?> ');</script>

Related Article

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.