我无法使用SQLITE数据库使此表单正常工作。我正在尝试将数据库的路径和文件保存到服务器。
我在想也许没有办法用SQLITE做到这一点。
index.php
<form method="post" action="upload.php" enctype="multipart/form-data">
<p>File :</p>
<input type="file" name="Filename">
<p>Description</p>
<textarea rows="10" cols="35" name="Description"></textarea>
<br/>
<input TYPE="submit" name="upload" value="Submit"/>
</form>
`upload.php
尝试将文件路径名插入sqlite数据库
<?php
$fileExistsFlag = 0;
$fileName = $_FILES['filename']['name'];
$link = class MyDB extends SQLite3 {
function __construct() {
$this->open('test.db');
}
}
$db = new MyDB();
if(!$db) {
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
};
/*
* Checking whether the file already exists in the destination folder
*/
$query = "SELECT filename FROM filedetails WHERE filename='$fileName'";
$result = $link->query($query);
while($row = sqlite_fetch_array($result, SQLITE_ASSOC)) {
if($row['filename'] == $fileName) {
$fileExistsFlag = 1;
}
}
/*
* If file is not present in the destination folder
*/
if($fileExistsFlag == 0) {
$target = "files/";
$fileTarget = $target.$fileName;
$tempFileName = $_FILES["filename"]["tmp_name"];
$fileDescription = $_POST['Description'];
$result = move_uploaded_file($tempFileName,$fileTarget);
/*
* If file was successfully uploaded in the destination folder
*/
if($result) {
echo "Your file <html><b><i>".$fileName."</i></b></html> has been successfully uploaded";
$query = "INSERT INTO filedetails(filepath,filename,description) VALUES ('$fileTarget','$fileName','$fileDescription')";
$link->query($query);
}
else {
echo "Sorry !!! There was an error in uploading your file";
}
}
/*
* If file is already present in the destination folder
*/
else {
echo "File <html><b><i>".$fileName."</i></b></html> already exists in your folder. Please rename the file and try again.";
}
?>