<form action="test.php" method="POST" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
这里处理的是图片,但没有使用mp3,mp4,我也改变了.ini文件中的upload_max_size但是这不起作用
$target_dir = "videos/";
echo '<br>';
echo $target_file = $target_dir . $_FILES['fileToUpload']['name'];
$uploadOk = 1;
echo '<br>';
//$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
echo 'started';
echo '<br>';
echo $check = $_FILES['fileToUpload']['tmp_name'];
if($check !== false) {
move_uploaded_file($check,$target_file);
echo 'Uploaded';
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
答案 0 :(得分:1)
看起来你应该设置其他php.ini变量,例如:
但是你总是可以发送大于这个限制的文件(然后超级全局_POST和_FILES都是空的)所以我认为最好的做法是使用这样的
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) &&
empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0 )
{
$displayMaxSize = ini_get('post_max_size');
switch ( substr($displayMaxSize,-1) )
{
case 'G':
$displayMaxSize = $displayMaxSize * 1024;
case 'M':
$displayMaxSize = $displayMaxSize * 1024;
case 'K':
$displayMaxSize = $displayMaxSize * 1024;
}
$error = 'Posted data is too large. '.
$_SERVER[CONTENT_LENGTH].
' bytes exceeds the maximum size of '.
$displayMaxSize.' bytes.";
}
代码ant解释可以在这里找到:http://andrewcurioso.com/blog/archive/2010/detecting-file-size-overflow-in-php.html