1
function addFlyer($db) {
if (isset($_FILES['file_array'])) {
$name_array = $_FILES['file_array']['name'];
$tmp_name_array = $_FILES['file_array']['tmp_name'];
$type_array = $_FILES['file_array']['type'];
$size_array = $_FILES['file_array']['size'];
$error_array = $_FILES['file_array']['error'];
for ($i = 0; $i < count($tmp_name_array); $i++) {
if (file_exists($name_array[$i])) {
echo "Sorry file already exists. ";
$uploadOk = 0;
}
else {
if (move_uploaded_file($tmp_name_array[$i], "images/" . $name_array[$i])) {
echo $name_array[$i] . " upload is complete<br>";
} else {
echo "move_uploaded_file function failed for " . $name_array[$i] . "<br>";
}
}
}
}
在我上传多个文件此代码到一个文件夹中的时刻,把它插入到数据库中(我排除的代码插入。)如何从数组中的文件名分解文件扩展名?
但是,如果我想使用file_exists正常工作,我需要从文件中分离扩展名和名称。但我不知道如何爆炸一个数组。
有没有人可以帮助我呢?
你好,谢谢你的回答。问题是,我想使用函数file_exists,并且该函数用它发送扩展..所以它不能正常工作。 – Patrick 2015-02-12 09:08:52
如果你想分解一个文件名。您可以使用以下技巧 $ file = $ _FILES ['file_array'] ['name']; $ image_info = explode(“。”,$ file); $ image_type = end($ image_info); – Vineet 2015-02-12 09:12:39