-1

I'm using BlueImp jQuery File Upload with database integration, adapting the script found here.

I changed a bit the handle_file_upload() method like this:

$sql = 'INSERT INTO '.$this->options['db_table'].' (`path`, `type`, `tab`, `item`) VALUES (?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
    'ssii',
    $path = $this->options['upload_url'] . $file->name,
    $file->type,
    $file->tab,
    $file->item
);

but, on the line $path = $this->options['upload_url'] . $file->name, I have a Strict Standards: Only variables should be passed by reference error

Well, I have no idea how to change this...

I tried to look at other answers, but they don't fit into my case: please any help? Thanks

Ivan
  • 2,463
  • 6
  • 39
  • 51
  • Create a new variable `$x = $this->options['upload_url'] . $file->name` and then bind `$x` as `path` – Mark Baker Jan 04 '16 at 19:59
  • Possible duplicate of [Strict Standards: Only variables should be passed by reference](http://stackoverflow.com/questions/2354609/strict-standards-only-variables-should-be-passed-by-reference) – Don't Panic Jan 04 '16 at 20:06

3 Answers3

4

Since it is passed by reference the variable needs to exist before binding

 $path = $this->options['upload_url'] . $file->name;
    $sql = 'INSERT INTO '.$this->options['db_table'].' (`path`, `type`, `tab`, `item`) VALUES (?, ?, ?, ?)';
    $query = $this->db->prepare($sql);
    $query->bind_param(
        'ssii',
        $path,
        $file->type,
        $file->tab,
        $file->item
    );
Mihai
  • 26,325
  • 7
  • 66
  • 81
  • 1
    Thanks, I should be a little bit tired :-)... I was trying something like `$tmp = $this->options['upload_url'] . $file->name;` ... `$path = $tmp` and it didn't work: I thought the problem was in the dot-chain, not in the assignment – Ivan Jan 04 '16 at 20:21
2

This should work...

$sql = 'INSERT INTO '.$this->options['db_table'].' (`path`, `type`, `tab`, `item`) VALUES (?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$p = $this->options['upload_url'] . $file->name;
$query->bind_param(
    'ssii',
    $p,
    $file->type,
    $file->tab,
    $file->item
);

You were setting $path's value in the parameter binding. So it wouldn't return anything.

Phiter
  • 14,570
  • 14
  • 50
  • 84
1

Read more here: Strict Standards: Only variables should be passed by reference

$sql = 'INSERT INTO '.$this->options['db_table'].' (`path`, `type`, `tab`, `item`) VALUES (?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$upload_url = $this->options['upload_url']  . $file->name;
$query->bind_param(
    'ssii',
    $path = $upload_url,
    $file->type,
    $file->tab,
    $file->item
);
Community
  • 1
  • 1
Kristiyan
  • 1,655
  • 14
  • 17