0

In my PHP application, users can choose to upload a file and this file will be stored in a table in my MySQL database.

On my XAMPP on Windows instance, this works fine. However, on AWS EC2 Ubuntu, when the form is submitted with a selected file, the web browser comes up with "Server Error 500 The website encountered an error while retrieving. It may be down for maintenance or configured incorrectly."

I initially checked the my.cnf file for the max_allowed_packet size, but this seems to fine as it was at default set to 16MB, however I have a feeling it's do with the Apache server itself not liking the upload of BLOBs.

Here is the PHP code that deals with inserting BLOBs to the table:

//execute stored proc. to upload attachment
$null = null;

$query = $this->connection->prepare("CALL sp_PopulateAbstractAttachments(?,?,?,?,?)");
$query->bind_param("ibssi", $abstractID, $null, $name, $type, $size) or die(mysqli_error($this->connection));
foreach (str_split($attachment, 10240) as $chunk)
{
   $query->send_long_data(1, $chunk);
}

$query->execute() or die(mysqli_error($this->connection));

$query->close();

Like I said, this works perfectly fine on XAMPP Windows, but not on AWS EC2 Ubuntu. What could be causing this issue?

EDIT

According to Apache's error log, this is the problem:

[Thu Jan 07 19:24:24.571319 2016] [:error] [pid 12049] [client XXX.XXX.XXX.XXX:XXXXX] PHP Fatal error: Call to a member function bind_param() on a non-object in /var/www/html/app/models/Abstracts.php on line 40, referer: http://XXXXXXXXXXX/public/index.php?url=home/submitAbstract/

What could the issue be?

randrade86
  • 346
  • 1
  • 10
RoyalSwish
  • 1,503
  • 10
  • 31
  • 57
  • You might need to increase the max_execution_time inside the php script itself. http://php.net/manual/en/function.set-time-limit.php for reference. – Derek Pollard Jan 07 '16 at 19:09
  • Error 500 doesn't tells us much. I suggest getting more info about your error in Ubuntu's server (apache2?) – randrade86 Jan 07 '16 at 19:10
  • @RodolfoAndrade Would you know how I could do that through SSH Client, as that's the only form of interaction I have with the server and I don't know Linux, unfortunately? Yes, it's apache2. – RoyalSwish Jan 07 '16 at 19:12
  • @DerekPollard I will have a look into that. – RoyalSwish Jan 07 '16 at 19:12
  • 1
    @RodolfoAndrade I found the error, please see post edit. – RoyalSwish Jan 07 '16 at 19:26
  • Try checking the following file: `/var/log/apache2/error.log`. You might need to `sudo` – randrade86 Jan 07 '16 at 19:27
  • @RodolfoAndrade I found the error, please see. Apparently it's saying that `$this->connection->prepare("...")` might be returning `false` as noted here: http://stackoverflow.com/a/17431062/2915050 – RoyalSwish Jan 07 '16 at 19:30
  • add: `if(false === $query) die($this->connection->error);` This should print your `prepare` call error – randrade86 Jan 07 '16 at 19:33
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100084/discussion-between-rodolfo-andrade-and-royalswish). – randrade86 Jan 07 '16 at 19:43

1 Answers1

0

hi here you can a little example

 if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) 
  { 
      $tmpName  = $_FILES['image']['tmp_name'];  

      $fp = fopen($tmpName, 'rb'); // read binary
  } 

  try
    {
        $stmt = $conn->prepare("INSERT INTO images ( picture ) VALUES ( ? )");
        $stmt->bindParam(1, $fp, PDO::PARAM_LOB);
        $conn->errorInfo();
        $stmt->execute();
    }
    catch(PDOException $e)
    {
        'Error : ' .$e->getMessage();
    }

for more information please check this link and find a example

insert with pdo php mysql blob

please try and good luck

BlackHack123
  • 349
  • 1
  • 10