Blueimp Custom Upload Handler
I've been trying to use my own PHP handler as i don't want to use the
provided one due to it being rather messy and i'm not sure how to work
within it.
However the code i made just to test the idea out, (doesn't have to output
the actual results, just want to output fixed values for now) but it kept
returning JSON.Parse unexpected characters. Any idea why?
My code is as follows
function upload(){
$fileCount = count($_FILES["files[]"]["name"]);
for($i=0; $i < $fileCount; $i++)
{
$fileName = $_FILES["files[]"]["name"][$i];
$ret['files'][$i]['name']= $fileName;
$ret['files'][$i]['size']= '1234';
$ret['files'][$i]['url']= 'http://example.org/logo.png';
$ret['files'][$i]['thumbnailUrl']= 'http://example.org/logo.png';
$ret['files'][$i]['deleteUrl']= 'http://example.org/logo.png';
$ret['files'][$i]['deleteType']= 'DELETE';
//move_uploaded_file($_FILES["files[]"]["tmp_name"][$i],$output_dir.$fileName
);
}
return json_encode($ret);
}
echo upload();
It's simply to get the result to show those, but somehow it doesn't work...
The JSON structure i'm supposed to achieve (Which i seem to do if i were
to run this function alone) is
{"files": [
{
"name": "picture1.jpg",
"size": 902604,
"url": "http:\/\/example.org\/files\/picture1.jpg",
"thumbnailUrl":
"http:\/\/example.org\/files\/thumbnail\/picture1.jpg",
"deleteUrl": "http:\/\/example.org\/files\/picture1.jpg",
"deleteType": "DELETE"
},
{
"name": "picture2.jpg",
"size": 841946,
"url": "http:\/\/example.org\/files\/picture2.jpg",
"thumbnailUrl":
"http:\/\/example.org\/files\/thumbnail\/picture2.jpg",
"deleteUrl": "http:\/\/example.org\/files\/picture2.jpg",
"deleteType": "DELETE"
}
]}
*Note: Example is for two files, theoretically mine should work.
No comments:
Post a Comment