我想上传一个SQLite数据库文件并在下一页显示。问题出在SQLite db文件的路径上。当我给出这条路径 uploads / test.db 而不是它的工作但当我通过 uploads / $ fname 给出路径时它不起作用。
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
Move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$fname = basename( $_FILES["fileToUpload"]["name"]);
echo $fname;
$db = new SQLite3('uploads/$fname');
$tablesquery = $db->query("SELECT name FROM sqlite_master WHERE type='table';");
while ($table = $tablesquery->fetchArray(SQLITE3_ASSOC)) {
if ($table['name'] != "sqlite_sequence") {
echo $table['name'] . ' <br />';
}
}
?>
答案 0 :(得分:1)
将您的添加到绝对本地路径。
$.post('endpoint/getTags.php', {}...
$target_dir = dirname(__FILE__) . "/uploads/";
So your final $$target_dir will be like /var/www/html/project/uploads/filename
永远不会创建文件夹,所以你应该自己创建了uploads文件夹。
答案 1 :(得分:1)
$fname
您使用的是单引号,而不是双引号,因此PHP的值不是expanding the variable uploads/$fname
。 PHP试图打开文字路径$db = new SQLite3("uploads/$fname");
,当然,没有找到任何东西。
将行更改为使用双引号,如下所示:
?