上传文件并将其移动到文件夹

时间:2018-02-12 21:45:25

标签: php fpdf

我有一个FPDF脚本,它提交PDF并将其移动到服务器上的文件夹中。

我在FPDF脚本运行之前在表单中有一个上传字段名为" file"

我正在尝试将其移动到与生成的PDF相同的文件夹中。

下面是我的代码:( PDF已生成并移动到文件夹,但上传的文件没有任何反应)

mkdir("claims/$name", 0777);

$move = "claims/$name";
foreach ($_FILES["files"]["tmp_name"] as $key => $value) 
{
 $tmp_name = $_FILES["files"]["tmp_name"][$key];
 $name2 = $move ."\\".basename($_FILES["files"]["name"][$key]);
 move_uploaded_file($tmp_name, $name2);
}

$filename = "claims/$name/$name.pdf";
$pdf->Output($filename, 'F');
header('Location: home.php');

1 个答案:

答案 0 :(得分:0)

我能够通过对代码进行一些更改来实现此功能。我还可以使用多个上传工作。

// make the directory
mkdir("claims/$name", 0777);

$total = count($_FILES['files']['name']);

// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['files']['tmp_name'][$i];

//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "claims/$name/" . $_FILES['files']['name'][$i];

//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {

}
}
}