基本上我想要完成的是使用具有以下功能的编辑器编辑器从文件夹中获取上传图像的列表:imageGetJson
我已经设法让 fwrite 在我的 images.json 文件中添加一个数组。现在的问题是,redactor 需要在输入周围加上括号才能渲染图像。
所以我的问题是如何获得数据周围的括号?
我到目前为止的上传文件是这样的:
// This is a simplified example, which doesn't cover security of uploaded images.
// This example just demonstrate the logic behind the process.
// files storage folder
$dir = '../img/uploads/';
$_FILES['file']['type'] = strtolower($_FILES['file']['type']);
if ($_FILES['file']['type'] == 'image/png'
|| $_FILES['file']['type'] == 'image/jpg'
|| $_FILES['file']['type'] == 'image/gif'
|| $_FILES['file']['type'] == 'image/jpeg'
|| $_FILES['file']['type'] == 'image/pjpeg')
{
// setting file's mysterious name
$filename = md5(date('YmdHis')).'.jpg';
$file = $dir.$filename;
// copying
copy($_FILES['file']['tmp_name'], $file);
// displaying file
$array = array(
'filelink' => '/img/uploads/'.$filename,
'thumb' => '/img/uploads/'.$filename,
'image' => '/img/uploads/'.$filename,
);
echo stripslashes(json_encode($array));
$json = stripslashes(json_encode($array)), "\n";
$files = fopen('../img/uploads/images.json','a+');
fwrite($files, $json . "\n");
fclose($files);
}
我制作了一个包含文件位置的数组并将其写入文件 images.json
我需要它的样子是这样的
[
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
]
只有它像这样添加:
[]
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
{"filelink":"image.jpg","thumb":"image.jpg","image":"image.jpg"}
希望有人可以帮助我,因为我无法弄清楚。
提前致谢