Re: [PHP-DB] Saving Image in mySQL

2013-03-20 Thread Jim Giner

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 variables

 $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);



And 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.  :)


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Saving Image in mySQL

2013-03-20 Thread Jim Giner
Absolutely - do not store any images in a db.  Makes no sense.  The data 
(the image) is static, basically safe from alteration or changing in any 
way, so what is the need?  Save the location/name of the image only and 
store all of them in one (or more) secured folders on the server.  No db 
overhead, no potential roadblocks as you grow your data tables and no 
excess time spent by the os storing and retrieving from the db.


Really - not a good idea.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Saving Image in mySQL

2013-03-20 Thread Toby Hart Dyke


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 variables

 $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);
 




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Saving Image in mySQL

2013-03-20 Thread Karl DeSaulniers

Ron,
If your hell bent on storing the image data. :P
I would say base64 the data and use a blob or text
then read it out using something like..

$image = '';
echo($image);

I would also say your individual image max size should be 50k or less.
If your storing product images for a catalog for instance, dont store  
image data, use the url instead.
If its ui images for a couple of web pages, then storing the image  
data wouldn't be a bad thing.

As long as the total size for all of your images is reasonable.
Your call.

Best,
Karl


On Mar 19, 2013, at 6:11 PM, Karl DeSaulniers wrote:


Hey Ron,
I don't know how others feel, but I say save yourself a headache and  
dont store the image data, just the url to the image on the server.


image_url – VARCHAR 100

Best,
Karl



On Mar 19, 2013, at 3: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


===

Filename:



===

mySQL table structure:
===
reference – INT 10 auto_increment primary
caption – VARCHAR 250
image_type – VARCHAR 100
image_size – INT 10
image_name – VARCHAR 100
image – LONGBLOB
===

Prepared Statement:

===
# mySQL query

  $query = "INSERT INTO `my_images` ( `reference` , `caption` ,  
`image_type` , `image_size` , `image_name` , `image` ) VALUES  
( NULL 
 , :caption , :image_type , :image_size , :image_name , :image );";


# apply query to Prepared Statement

  if($stmt = $dbh->prepare( $query )) {

# bind variables

  $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);

# execute query

  if ( $stmt->execute() or die(print_r($stmt->errorInfo(),  
true)) ) {


# retrieve auto_increment value

  $new_record_reference = $dbh->lastInsertId();

  }

  }
===


Ron Piggott



www.TheVerseOfTheDay.info


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Saving Image in mySQL

2013-03-20 Thread Gavin Chalkley
I am with Karl on this.

Storing an image in the db is very heavy on lpad times.

Upload the image to a folder with name saved with location
On Mar 19, 2013 11:12 PM, "Karl DeSaulniers"  wrote:

> Hey Ron,
> I don't know how others feel, but I say save yourself a headache and dont
> store the image data, just the url to the image on the server.
>
> image_url – VARCHAR 100
>
> Best,
> Karl
>
>
>
> On Mar 19, 2013, at 3: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
>>
>> ===
>> > enctype="multipart/form-data">
>> Filename:
>> 
>> 
>> 
>> ===
>>
>> mySQL table structure:
>> ===
>> reference – INT 10 auto_increment primary
>> caption – VARCHAR 250
>> image_type – VARCHAR 100
>> image_size – INT 10
>> image_name – VARCHAR 100
>> image – LONGBLOB
>> ===
>>
>> Prepared Statement:
>>
>> ===
>> # mySQL query
>>
>>$query = "INSERT INTO `my_images` ( `reference` , `caption` ,
>> `image_type` , `image_size` , `image_name` , `image` ) VALUES ( NULL ,
>> :caption , :image_type , :image_size , :image_name , :image );";
>>
>> # apply query to Prepared Statement
>>
>>if($stmt = $dbh->prepare( $query )) {
>>
>> # bind variables
>>
>>$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);
>>
>> # execute query
>>
>>if ( $stmt->execute() or die(print_r($stmt->errorInfo()**,
>> true)) ) {
>>
>> # retrieve auto_increment value
>>
>>$new_record_reference = $dbh->lastInsertId();
>>
>>}
>>
>>}
>> ===
>>
>>
>> Ron Piggott
>>
>>
>>
>> www.TheVerseOfTheDay.info
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP-DB] Saving Image in mySQL

2013-03-19 Thread Karl DeSaulniers

Hey Ron,
I don't know how others feel, but I say save yourself a headache and  
dont store the image data, just the url to the image on the server.


image_url – VARCHAR 100

Best,
Karl



On Mar 19, 2013, at 3: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


===

Filename:



===

mySQL table structure:
===
reference – INT 10 auto_increment primary
caption – VARCHAR 250
image_type – VARCHAR 100
image_size – INT 10
image_name – VARCHAR 100
image – LONGBLOB
===

Prepared Statement:

===
# mySQL query

   $query = "INSERT INTO `my_images` ( `reference` , `caption` ,  
`image_type` , `image_size` , `image_name` , `image` ) VALUES  
( NULL 
 , :caption , :image_type , :image_size , :image_name , :image );";


# apply query to Prepared Statement

   if($stmt = $dbh->prepare( $query )) {

# bind variables

   $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);

# execute query

   if ( $stmt->execute() or die(print_r($stmt->errorInfo(),  
true)) ) {


# retrieve auto_increment value

   $new_record_reference = $dbh->lastInsertId();

   }

   }
===


Ron Piggott



www.TheVerseOfTheDay.info


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Saving Image in mySQL

2013-03-19 Thread Ron Piggott

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

===

Filename:



===

mySQL table structure:
===
reference – INT 10 auto_increment primary
caption – VARCHAR 250
image_type – VARCHAR 100
image_size – INT 10
image_name – VARCHAR 100
image – LONGBLOB
===

Prepared Statement:

===
# mySQL query

$query = "INSERT INTO `my_images` ( `reference` , `caption` , `image_type` 
, `image_size` , `image_name` , `image` ) VALUES ( NULL , :caption , 
:image_type , :image_size , :image_name , :image );";

# apply query to Prepared Statement

if($stmt = $dbh->prepare( $query )) {

# bind variables

$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);

# execute query

if ( $stmt->execute() or die(print_r($stmt->errorInfo(), true)) ) {

# retrieve auto_increment value

$new_record_reference = $dbh->lastInsertId();

}

}
===


Ron Piggott



www.TheVerseOfTheDay.info