我正在尝试使用php上传文件。代码似乎适用于图像文件,但它不适用于mp4。我更改了大文件的php.ini标志,但它仍然无法正常工作。这是我的html表单:(代码来自http://www.w3schools.com/php/php_file_upload.asp)
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload File" name="submit">
</form>
</body>
</html>
这是upload.php文件:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
echo $target_file; // does not return the file name for mp4 files but it works for jpeg file.
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "mp4") {
echo "Sorry, only JPG, JPEG, PNG & GIF & mp4 files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
以下是我在php.ini文件中设置的php标志:
post_max_size = 1G
upload_max_filesize = 900M
file_uploads = On
max_execution_time = 300
memory_limit = 1G
我正在使用php 7.0。我无法想到我应该做的任何其他事情,以使这项工作,任何评论表示赞赏!