我已经尝试了本节中的所有内容,并且我知道这是我忘记的东西。无论我添加什么都会停止上传,但目前正在努力在服务器上获取图像。
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index) {
$file = new stdClass();
$file->name = $this->trim_file_name($name, $type, $index);
$file->size = intval($size);
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$file_path = $this->options['upload_dir'].$file->name;
$append_file = !$this->options['discard_aborted_uploads'] &&
is_file($file_path) && $file->size > filesize($file_path);
clearstatcache();
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
$file_size = filesize($file_path);
if ($file_size === $file->size) {
if ($this->options['orient_image']) {
$this->orient_image($file_path);
}
$file->url = $this->options['upload_url'].rawurlencode($file->name);
foreach($this->options['image_versions'] as $version => $options) {
if ($this->create_scaled_image($file->name, $options)) {
if ($this->options['upload_dir'] !== $options['upload_dir']) {
$file->{$version.'_url'} = $options['upload_url']
.rawurlencode($file->name);
} else {
clearstatcache();
$file_size = filesize($file_path);
}
}
}
} else if ($this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = 'abort';
}
$file->size = $file_size;
$this->set_file_delete_url($file);
}
return $file;
}
在它上传它连接到数据库并将文件 url 发布到我需要的字段后,我将如何做到这一点。
我一直在上面插入它,它只是导致它不起作用:
$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 ('', 'test_upload_file_name')");
mysql_close($con);
header("Location: http://-----.com/index.php");
提前谢谢。