我使用Bootstrap作为我的前端框架,使用以下代码上传文件。
<form method="POST" enctype="multipart/form-data" action= "php/up-load.php" role="form"
<div class="form-group">
<label for="file" class="col-sm-5 control-label">
Select file(Compressed format)
</label>
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000"/>
<input type="file" id="file" name="file" accept=".zip, .rar"/>
</div>
</div>
<div>
<button type="submit" class="btn btn-primary" name="upload" id="upload">Send</button>
</div>
</form>
我的PHP代码是;
@ $original=$_FILES['file']['name'];
@ $kiss=pathinfo($original, PATHINFO_EXTENSION);
$allowed_extensions = array(".zip","rar","bzip2","iso","gz","rz","7z","tar","tgz","bz2","tbz2","lzma","tlz");
$result = in_array ("$kiss", $allowed_extensions);
if (!$result)
{
// Wrong file type
}
else
{
//proceed..
}
我的问题是
$_FILES['file']['name'];
正在返回php7vy8X9
和phpY8wQVR
等乱码。尝试了一切。可能是什么问题?
答案 0 :(得分:0)
$_FILES["file"]["name"]
应该返回您文件的原始名称,您报告的内容应该存储在$_FILES["file"]["tmp_name"]
整个$_FILES
数组应该如下所示:
echo $_FILES["file"]["name"]; // Original Name
echo $_FILES["file"]["tmp_name"]; // Name (and location) given to the file by PHP
echo $_FILES["file"]["type"]; // File/mime type
echo $_FILES["file"]["size"]; // Total bytes
echo $_FILES["file"]["error"]; // Any error code which is returned during transfer