0

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!

2 Answers 2

0

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;
}
Sign up to request clarification or add additional context in comments.

3 Comments

i get this error: <b>Fatal error</b>: Cannot use object of type UploadHandler as array in <b>/Applications/XAMPP/xamppfiles/htdocs/villalba2/admin/server/php/index.php</b> on line <b>43</b><br />
What variable holds that json you posted?
this variables are printed on the browser by $upload_handler = new UploadHandler($options);
0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.