0

我正在尝试使用以下代码在一个提交按钮中上传两个文件:

<label>Logo Image *</label>
<input type="file" name="ufile[]"/>
<label>Banner Image *</label>
<input type="file" name="ufile[]"/>

PHP

$logo = $_FILES['ufile']['name'][0];
$block_img = $_FILES['ufile']['name'][1];

 if ($_FILES['ufile']['name']["error"] > 0) {
    echo "error<br>";
   }
  else {
    if (file_exists("small-image/" .  $_FILES['ufile']['name'][0])){
        echo $_FILES['ufile']['name'][1] . "File already exists in server. ";
    }
    else {
        move_uploaded_file($_FILES['ufile']['name'][0], "small-image/" . $_FILES['ufile']['name'][0]);
        move_uploaded_file($_FILES['ufile']['name'][1], "small-image/" . $_FILES['ufile']['name'][1]);
    }
 }

$sql_query = "UPDATE header_img SET logo_img = '$logo', block_img = '$block_img' WHERE banner_id = 1";

我的数据库正在正确更新,但文件未上传。是的,有一个 777 目录调用“小图像”。

任何的想法?谢谢。

4

1 回答 1

1

当您使用 时move_uploaded_file,您想使用$_FILES['ufile']['tmp_name'],即文件当前所在的位置。

move_uploaded_file($_FILES['ufile']['tmp_name'][0], "small-image/" . $_FILES['ufile']['name'][0]);
move_uploaded_file($_FILES['ufile']['tmp_name'][1], "small-image/" . $_FILES['ufile']['name'][1]);

检查文档中的示例:http: //php.net/manual/en/function.move-uploaded-file.php

于 2013-07-08T19:29:36.520 回答