我正在尝试将文件路径上传到我的文件表中,但收效甚微。我使用dropzone.js lib来处理拖放上传。我可以成功地将文件插入上传文件,但我很难获得在表中创建行的路径:
以下是我创建表单的方法:
<form action="actions/file-upload.php" class="dropzone">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</form>
<?php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '../uploads'; //2
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
//insert file information into db table
$conn->query("INSERT INTO files (name) VALUES('$tempFile')");
}
}
?>
我在SO上有类似的线索,但没什么明显的......