Basicly what i am trying to accomplish is to get a list of uploaded images from a folder using the editor redactor with the function: imageGetJson
I have managed to get fwrite to add an array in my images.json file. Now the problem is that redactor needs brackets around the input in order to render the images.
So my question is how do i get the brackets around my data?
The upload file i have so far is this:
// 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)), "
";
$files = fopen('../img/uploads/images.json','a+');
fwrite($files, $json . "
");
fclose($files);
}
I have made an array that contains the file location and wrote it to the file images.json
The way i need it to look is like this
[
{"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"}
]
Only it adds like this:
[]
{"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"}
Hope someone can help me with this because i cant figure it out.
Thanks in advance :D