PHP上传无法上传到服务器

时间:2016-05-27 18:19:36

标签: php html mysql upload

我正在尝试编写一个上传脚本来将文件放入服务器并将值回显到数据库中...不用说它不起作用并且它返回脚本底部的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,所有其他数据都正确发布。

1 个答案:

答案 0 :(得分:-1)

 If( isset($_FILES["sponsors"]["name"])){}

这将检查文件名是否实际通过

传递

以下链接明确说明了如何在PHP http://www.w3schools.com/php/php_file_upload.asp

中处理文件上传