[英]Uploading file is not working with mp3 and mp4
<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>
here this is working with images but not working with mp3,mp4,I've changed the upload_max_size in .ini file also but that doesn't work在这里,这是处理图像,但不适用于 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;
}
}
?>
It's look like you should also set the other php.ini variables for example:看起来您还应该设置其他 php.ini 变量,例如:
But then you could always send file larger than this limit (then the superglobal _POST and _FILES are empty) so the best practice I think is to use sth like this但是你总是可以发送大于这个限制的文件(然后超全局 _POST 和 _FILES 是空的)所以我认为最好的做法是像这样使用 sth
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.";
}
The code ant explain could be found here: http://andrewcurioso.com/blog/archive/2010/detecting-file-size-overflow-in-php.html代码蚂蚁解释可以在这里找到: http : //andrewcurioso.com/blog/archive/2010/detecting-file-size-overflow-in-php.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.