i use blueimp jquery for upload files. the files are upload perfect but now i need recovery the name files for insert into my database.
In index.php (server/php) i have this:
session_start();
include_once('../../include/database.php');
error_reporting(E_ALL | E_STRICT);
require_once('UploadHandler.php');
define("DIR_DOWNLOAD", "/Applications/XAMPP/htdocs/villalba2");
define("HTTP_SERVER", "/villalba2");
$cat=$_SESSION['nombre'];
$id_cat=$_SESSION['id_cat'];
$options = array(
'upload_dir' => DIR_DOWNLOAD . '/uploads/' . $cat. '/',
'upload_url' => HTTP_SERVER . '/uploads/' . $cat. '/',
);
$upload_handler = new UploadHandler($options);
I need recovery a file names in order to insert into my database.
the json create by blueimp is:
Array
(
[files] => Array
(
[0] => stdClass Object
(
[name] => project-1.jpg
[size] => 69077
[url] => /villalba2/uploads/Mobiliario/project-1.jpg
[thumbnailUrl] => /villalba2/uploads/Mobiliario/thumbnail/project-1.jpg
[deleteUrl] => http://localhost/villalba2/admin/server/php/?file=project-1.jpg
[deleteType] => DELETE
)
[1] => stdClass Object
(
[name] => project-2.jpg
[size] => 42109
[url] => /villalba2/uploads/Mobiliario/project-2.jpg
[thumbnailUrl] => /villalba2/uploads/Mobiliario/thumbnail/project-2.jpg
[deleteUrl] => http://localhost/villalba2/admin/server/php/?file=project-2.jpg
[deleteType] => DELETE
)
[2] => stdClass Object
(
[name] => project-7.jpg
[size] => 91440
[url] => /villalba2/uploads/Mobiliario/project-7.jpg
[thumbnailUrl] => /villalba2/uploads/Mobiliario/thumbnail/project-7.jpg
[deleteUrl] => http://localhost/villalba2/admin/server/php/?file=project-7.jpg
[deleteType] => DELETE
)
)
)
How to acces into the json from PHP for recovery the file name?? thanks!
Use it as you would use any other array, ie:
$filename = $upload_handler['files'][0]->name;
or to loop through all you could simply do:
foreach($upload_handler['files'] as $file)
{
$filename = $file->name;
}
I solved my problem adding the database into the UploadHanler.php following this post
adding the uploaded file name to database in blueimp fileupload jquery plugin
But now i get an error in the browser " SyntaxError: Unexpected token < ".
The data is stored in the database and in your folder. But i get this error, why ??
Thanks!