Re: Saving Image in mySQL
| From: | Jim Giner | Date: | Wed, 20 Mar 2013 13:12:00 +0000 |
| Subject: | Re: Saving Image in mySQL | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-48708@lists.php.net to get a copy of this message | ||
On 3/20/2013 8:43 AM, Toby Hart Dyke wrote:
You're right - you're pulling $file out of thin air. Once uploaded, the file is stored in $_FILES['file']['tmp_name'], and you need to manually read the data into $file yourself. Something like: file_get_contents($_FILES['file']['tmp_name']) Toby On 3/19/2013 8:15 PM, Ron Piggott wrote:Hi All I don’t understand how to save an image to a mySQL table based on the following form. I am trying to do this using Prepared Statements. All the fields except the image file itself save in the database. Right now I have $file as the variable when binding the values. What should it be? Ron# bind variablesAnd in doing this your destination would then be the final resting place for the image(s), with the pointer to each stored in your table record for that image. :)$stmt->bindValue(':caption', 'Test Caption', PDO::PARAM_STR); $stmt->bindValue(':image_type', $_FILES["file"]["type"],PDO::PARAM_STR);$stmt->bindValue(':image_size', $_FILES["file"]["size"],PDO::PARAM_INT);$stmt->bindValue(':image_name', $_FILES["file"]["name"],PDO::PARAM_STR);$stmt->bindValue(':image', $file, PDO::PARAM_STR);