【发布时间】:2016-10-05 13:44:28
【问题描述】:
我写了这段代码来上传我的mysql数据库中的文件信息:
<?php
require __DIR__ . '/database.php';
$file = $_GET["item"];
$itemName = $_GET["itemName"];
$uploadDate = filectime($file);
$filePathArray = pathinfo($file);
$filePath = $filePathArray["filename"];
$stmt = db()->prepare("INSERT INTO items (id, itemName, uploadDate, filePath) VALUES ('','{$itemName}','{$uploadDate}','{$filePath}");
$stmt->execute();
?>
HTML代码:
<form action="upload_action.php">
Item Name:<br>
<input type="text" name="itemName"><br>
File:<br>
<input type="file" name="item"><br>
<input type="submit" name="submit">
</form>
但我总是得到“filectime(): stat failed”和致命错误.. 不知道为什么。你能帮我改正我的代码吗,我会很高兴
【问题讨论】:
-
文件需要 post 方法和有效的 enctype 并使用
$_FILES,而不是$_GET。认为这是一个“答案”。 -
感谢您的回答,但现在我收到如下错误:filectime() 期望参数 1 也是有效路径,而 pathinfo() 也是有效字符串