-1

我必须与当前存在的相对愚蠢的系统集成。因此,愚蠢的代码。我需要的是让用户选择要上传的pdf。然后将 pdf 保存为 cusip_HLD.pdf 以保存尽可能多的 cusip。例如

$fundID = 8
SELECT cusip FROM shareClass WHERE fundID = '$fundID'

将返回

|  CUSIP  |
| 1234567 |
| 7894561 |
| 3546841 |

当前存在的代码如下,但虽然它会重复保存多次,但move_uploaded_file似乎会将文件从临时存储中拉出。

while($row = mysql_fetch_assoc($getCusipsResult)){
        $cusip = $row['cusip'];
        $fullFileName = $cusip."_HLD.pdf";
        move_uploaded_file($_FILES["file"]["tmp_name"], "pdf/".$fullFileName);
        echo "Stored in: pdf/".$fullFileName;
    }

编辑:如何修复代码以满足上述需求?

4

1 回答 1

1

您只能移动一次上传的文件。之后它不再在临时上传目录中(因为你移动了它)。如果您需要创建文件的多个副本,请改用copy命令,例如

while($row = ...) {
  $fullFileName = ...;
  if (is_uploaded_file($_FILES['file']['tmp_name'])) {
      copy($_FILES['file']['tmp_name'], "pdf/$fullFileName");
  }
}

if these files are not going to be modified by the users, then consider using a hardlink instead, so only one copy of the file is saved, and simply point the other "copies" at the original.

于 2013-01-16T18:56:03.617 回答