【发布时间】:2014-04-08 14:16:44
【问题描述】:
我已经四处搜索并尝试了所有方法,我的脚本运行良好并且我正在正确上传文件,但现在我不知道为什么它仍然会抛出我的数组中确实存在的文件扩展名错误。
这是我的 PhpUpload 脚本:
<?php
# code...
if(!@include("bootstrap.php")) throw new Exception("Failed to include 'bootstrap'");
else{
$sqldb=new SqlDB;
$mysqli=$sqldb->DBconnect('localhost','root','root','dbex');
if (isset($_GET['ref']) && isset($_GET['rooms']) && isset($_GET['showers']) && isset($_GET['parkings']) && isset($_GET['infos']) && isset($_GET['city']) && isset($_GET['surface']) && isset($_GET['price']) && isset($_GET['sup']) && isset($_GET['desc'])) {
# code...
if (!empty($_GET['ref']) && !empty($_GET['rooms']) && !empty($_GET['showers']) && !empty($_GET['parkings']) && !empty($_GET['infos']) && !empty($_GET['city']) && !empty($_GET['surface']) && !empty($_GET['price']) && !empty($_GET['sup']) && !empty($_GET['desc'])) {
# code...
$ref = $_GET['ref'];
$rooms = $_GET['rooms'];
$showers = $_GET['showers'];
$parkings = $_GET['parkings'];
$infos = $_GET['infos'];
$city = $_GET['city'];
$surface = $_GET['surface'];
$price = $_GET['price'];
$sup = $_GET['sup'];
$desc = $_GET['desc'];
//File size, path and extensions allowed
$allowed_filetypes = array('.jpg','.jpeg','.png','.gif');
$max_filesize = 10485760;
$path="css/";
//File name
$i=10;
//File settings
$filename = $_FILES['file']['name'];
$uploadfile=$path.basename($filename);
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
//Conditions
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if(filesize($_FILES['fileselect']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if (file_exists($upload_path))
die('File already exist.');
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
# code...
die('Line 41');
}
else{
die('error uploading the file');
}
}
}
}
?>
当我尝试上传我的数组中存在的带有“.gif”和“.jpg”扩展名的图像时,它说该文件是不允许的。
HTML 表单代码(Bootstrap CSS & Js):
<form role="form" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group has-feedback">
<label class="control-label col-sm-3" for="fileselect">Images :</label>
<div class="col-sm-9 upload">
<!-- Change the wording using a title tag -->
<input type="file" title="Parcourir..." name="file" multiple="multiple" id="file"/>
<span class="messages" id="file-name"></span>
</div>
</div>
<div class="form-group pull-right">
<div class="col-sm-9">
<button type="submit" class="btn btn-success" id="submit" name="submit" value="addPro">Ajouter ce bien</button>
</div>
</div>
</form>
谢谢你们!
【问题讨论】:
-
尝试将
enctype="multipart/form-data"添加到您的<form> -
已经试过不行了。
-
这就是我将其作为评论发布的原因。当涉及到这样的问题时,我知道它不能 100% 确定它会起作用,并且可能是其他原因导致了问题。
-
我想我知道为什么。您可能存在命名约定冲突。
-
你的意思是在我的html输入文件标签中的type、name和id之间?
标签: php twitter-bootstrap file-upload