私はこのセクション内のすべてを試しましたが、私が忘れているのは愚かなことであることを知っています. 何を追加してもアップロードは停止しますが、これは現在、サーバー上で画像を取得するために機能しています。
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");
ありがとうございます。