我正在尝试编写一个上传脚本来将文件放入服务器并将值回显到数据库中...不用说它不起作用并且它返回脚本底部的echo。我不知道它有什么问题:/
if (isset($_POST['title'])) {
$mysqli = new mysqli('..', '..', '..', '..');
$mysqli->query('INSERT INTO event-archive SET (`title`,`date`,`time_start`,`time_end`,`region`,`description`,`sponsors`,`embed`,`event-type`,`recording-type`,`additional-information`) VALUES (' . addslashes($_POST['title']) . ',' . addslashes($_POST['date']) . ',' . intval($_POST['time-start']) . ',' . intval($_POST['time-end']) . ',' . addslashes($_POST['region']) . ',' . addslashes($_POST['description']) . ',' . addslashes($_POST['sponsors']) . ',' . addslashes($_POST['embed']) . ',' . addslashes($_POST['event-type']) . ',' . addslashes($_POST['recording-type']) . ',' . addslashes($_POST['additional-information']) . ')');
if (isset($_FILES["sponsors"])){
$target_dir = "path";
$info = new SplFileInfo($target_dir . basename($_FILES["sponsors"]));
$newfile = time() . '.' . $info->getExtension();
$target_file = $target_dir . $newfile;
if (move_uploaded_file($_FILES["sponsors"], $target_file)) {
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$mysqli->close();
exit;
}
我在表单上有enctype,所有其他数据都正确发布。
答案 0 :(得分:-1)
If( isset($_FILES["sponsors"]["name"])){}
这将检查文件名是否实际通过
传递以下链接明确说明了如何在PHP http://www.w3schools.com/php/php_file_upload.asp
中处理文件上传