1

所以这个语法确实连接并获取发布到数据库的信息,但我不知道如何获取图像的 url 以发布到数据库。无论我将 test1 更改为什么,它都不会发布。

protected function trim_file_name($name, $type, $index) {
    // Remove path information and dots around the filename, to prevent uploading
    // into different directories or replacing hidden system files.
    // Also remove control characters and spaces (\x00..\x20) around the filename:
    $file_name = trim(basename(stripslashes($name)), ".\x00..\x20");
    // Add missing file extension for known image types:
    if (strpos($file_name, '.') === false &&
        preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
        $file_name .= '.'.$matches[1];
    }
    if ($this->options['discard_aborted_uploads']) {
        while(is_file($this->options['upload_dir'].$file_name)) {
            $file_name = $this->upcount_name($file_name);
        }
    }
    $con = mysql_connect("localhost","-----","-----");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("-----", $con);

    mysql_query("INSERT INTO posts (postid, post_content)
    VALUES ('', 'test1')");

    mysql_close($con);
    {
    header("Location: http://snarb.com/index.php");
    }
    return $file_name;

}
4

1 回答 1

0

将您的 mysql_query 行更改为:

 mysql_query("INSERT INTO posts (post_content) VALUES ('" . mysql_real_escape_string($file_name) . "')");
于 2013-03-24T18:53:08.927 回答