我需要以逗号分隔的所有图像名称。Bcoz 我需要以逗号分隔的形式在 DB 中插入名称。
我正在尝试在 handle_file_upload() 函数中这样做
$arrOfImgs = 数组($file->name); $comma_separated = implode(",", $arrOfImgs);
并将其传入
$file->upload_to_db = $this->add_img($comma_separated);
但是越来越失败。
请帮忙..
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = new stdClass();
$file->name = $this->trim_file_name($name, $type, $index, $content_range);
$arrOfImgs = array($file->name);
$comma_separated = implode(",", $arrOfImgs);
$file->size = $this->fix_integer_overflow(intval($size));
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
mkdir($upload_dir, $this->options['mkdir_mode'], true);
}
$file_path = $this->get_upload_path($file->name);
$append_file = $content_range && is_file($file_path) &&
$file->size > $this->get_file_size($file_path);
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 = $this->get_file_size($file_path, $append_file);
if ($file_size === $file->size) {
if ($this->options['orient_image']) {
$this->orient_image($file_path);
}
$file->url = $this->get_download_url($file->name);
foreach($this->options['image_versions'] as $version => $options) {
if ($this->create_scaled_image($file->name, $version, $options)) {
if (!empty($version)) {
$file->{$version.'_url'} = $this->get_download_url(
$file->name,
$version
);
} else {
$file_size = $this->get_file_size($file_path, true);
}
}
}
} else if (!$content_range && $this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = 'abort';
}
$file->upload_to_db = $this->add_img($comma_separated);
$file->size = $file_size;
$this->set_file_delete_properties($file);
}
return $file;
}