路径:D:/apmxe/htdocs/vip.bearing.cn/plateform/photo/
文件类型:'image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','image/x-png','text/x-vcard'<input name="upfile" id="upfile" type="file" class="viewBorder"/><input name="input" type="button" class="buttonBg" value="上传" onclick="Submit_UploadPic();" />
文件类型:'image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','image/x-png','text/x-vcard'<input name="upfile" id="upfile" type="file" class="viewBorder"/><input name="input" type="button" class="buttonBg" value="上传" onclick="Submit_UploadPic();" />
<?php
// a.php
if(isset($_FILES['upfile']) && $_FILES['upfile']['name']){
$file = $_FILES['upfile'];
switch($file['error']){
case 1:
exit('The uploaded file exceeds the upload_max_filesize in php.ini option to limit values.');
case 2:
exit('Upload file size exceeds the specified HTML form MAX_FILE_SIZE option value.');
case 3:
exit('File only partially uploaded.');
case 4:
exit('No file was uploaded.');
default:
$allow_types = array(
'image/jpg' => 'jpg',
'image/jpeg' => 'jpg',
'image/pjpeg' => 'jpg',
'image/png' => 'png',
'image/x-png' => 'png',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'text/x-vcard' => 'txt'
);
if(!isset($allow_types[$file['type']])){
exit('Does not support the type of your upload.');
}
$save_path = 'D:/apmxe/htdocs/vip.bearing.cn/plateform/photo';
if(!is_dir($save_path)){
mkdir($save_path, 0777, true);
}
if(!is_writeable($save_path)){
exit('Folder is not write.');
}
$file_name = time() . rand(1000, 9999) . '.' . $allow_types[$file['type']];
while(is_file($save_path . $file_name)){
$file_name = time() . rand(1000, 9999) . '.' . $allow_types[$file['type']];
}
$upload = move_uploaded_file($file['tmp_name'], $save_path . $file_name);
if(!$upload){
exit('Upload Failed.');
}
echo 'Upload success.';
}
}
?>
<form enctype="multipart/form-data" action="a.php" method="post">
<input type="hidden" name="max_file_size" value="100000">
<input name="upfile" type="file">
<input type="submit" value="upload">
</form>