Using jQuery-File-Upload How to pick the image path to save in the database?

1,553 views
Skip to first unread message

samuelr

unread,
May 22, 2013, 1:49:53 PM5/22/13
to jquery-f...@googlegroups.com




 Good morning,

 I'm trying to use this plugin jquery "https://github.com/blueimp/jQuery-File-Upload" For sending files.

 Except that I am not able to get the url return to save in the database.

 I need the path where the image was sent to save.

 How and where can I get this way?

Hermie Barit

unread,
Jul 8, 2013, 3:17:43 AM7/8/13
to jquery-f...@googlegroups.com
Hello,

follow this steps:

https://github.com/blueimp/jQuery-File-Upload/wiki/Working-with-databases

then, in UploadHandler.php... go to function handle_file_upload()...add this line:

$file->url = $this->get_download_url($file->name);

right after the

$file_size = $this->get_file_size($file_path, $append_file);

then, add the parameter in the following code:

$file->upload_to_db = $this->add_img($product,$file->name,$file->url,$file_size);

hope it helps.. :)

Mickey K

unread,
Oct 4, 2013, 8:06:16 PM10/4/13
to jquery-f...@googlegroups.com
Hello Hermie
I'm trying to follow you're instructions but a Can't find the reference to
$file->upload_to_db = $this->add_img($product,$file->name,$file->url,$file_size);
in the UploadHandler.php file?
Were would i find it.
Thanks
Mickey
Message has been deleted

Jason Demetri

unread,
Dec 31, 2013, 11:28:48 AM12/31/13
to jquery-f...@googlegroups.com
Hi Mickey,

I figured it out... I did not add this: $file->upload_to_db = $this->add_img($product,$file->name,$file->url,$file_size); but instead in the index.php file in the protected function handle_file_upload I added `url` to the INSERT query along with the additional ? in the VALUES and s in the bind_param as well as $file_url so my new function looks like this:

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
            $index = null, $content_range = null) {
        $file = parent::handle_file_upload(
        $uploaded_file, $name, $size, $type, $error, $index, $content_range
        );
        if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `url`, `title`, `description`)'
.' VALUES (?, ?, ?, ?, ?, ?)';
       $query = $this->db->prepare($sql);
       $query->bind_param(
        'sissss',
        $file->name,
        $file->size,
        $file->type,
$file->url,
        $file->title,
        $file->description
       );
       $query->execute();
       $file->id = $this->db->insert_id;
        }
        return $file;
    }

Hope this helps

God bless
jason
Reply all
Reply to author
Forward
0 new messages