我的代码
我有这种多部分形式:
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file"><span>Select:</span></label>
<input type="file" name="file" id="file">
<br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Upload">
</form>
指向此文件:
<?php
$allowedExts = array("mp4", "avi","mpeg","wmv","swf","3gp","AVI");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if (!in_array($extension, $allowedExts) || $_FILES['file']['error']>0 || file_exists(date("YmdHis").$_FILES["file"]["name"]))
{
echo "Error [code: ".$_FILES['file']['error']."]";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
date("YmdHis").$_FILES["file"]["name"]);
echo 'file uploaded';
}
?>
它应该做什么
上传视频文件
什么不行?
我尝试上传大约300kb的.AVI视频:已上传,但错误消息&#34;错误[代码:]&#34;显示
error_reporting(E_ALL);
注意:未定义索引:第5行upload.php中的文件
注意: 未定义的索引:第8行的upload.php文件
var_dump($_POST,$_FILES);
的结果(&#34;密码&#34;字段为空)
array(0) { } array(0) { }
"<pre>"; print_r($_FILES);
Array ( )
我在哪里尝试了代码
我的问题
如何正确显示成功消息并解决问题?
答案 0 :(得分:0)
它正在发生,因为文件sieze。 -
; Maximum allowed size for uploaded files.
upload_max_filesize = allowed max size
; Must be greater than or equal to upload_max_filesize
post_max_size = allowed max size
答案 1 :(得分:0)
我在PHP 5.3.18上运行了你的代码。 Windows XP。假设满足上传限制。我能找到的唯一问题是你在移动文件时错过了“目标文件名”中的“目标”目录。
经过测试的示例代码:
<?php // http://stackoverflow.com/questions/25115575/file-uploader-uploading-files-but-displaying-error?noredirect=1#comment39103445_25115575
$destDir = 'P:/temp/';
$allowedExts = array("mp4", "avi","mpeg","wmv","swf","3gp","avi");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if (!in_array($extension, $allowedExts) || $_FILES['file']['error']>0 || file_exists(date("YmdHis").$_FILES["file"]["name"]))
{
echo "Error [code: ".$_FILES['file']['error']."]";
} else {
$newFilename = $destDir . date("YmdHis").$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],
$newFilename);
echo 'file uploaded : ', $newFilename;
}