Jump to content

[SOLVED] Can't save image into MySQL column.


DataRater

Recommended Posts

All I can put in is the name of the image i.e. 'MissSilver.jpg'

 

In the insert statement 'name' is a varchar for the filename and 'picture' is a blob for the image. Both columns end up with the name 'MissSilver.jpg' in them. How do I store the image?

 

Here is the code

 

<?php

require_once 'MySQL5.php';

?>

<head>

<title>Load image into database</title>

</head>

<body>

<?php

if (isset($_POST['file'])){

  $file=$_POST['file'];

 

  $YSLink=DBConnection('database');

 

  if(!$YSLink) {

    echo "Failed to connect to the server";

    }

 

  $sql=sprintf(

            "insert into pictures (name,picture)VALUES('%s','%s')",

              mysqli_real_escape_string($YSLink,$file),

              mysqli_real_escape_string($YSLink,$file)

              );

 

  $ResultSet = GetResultOfQuery($YSLink,$sql);

 

  if ($ResultSet) {

    echo "Inserted<br />";

    }

  else{

    echo "Not inserted<br />";

    }

  }

?>

<?php echo date('l jS \of F Y h:i:s A') ?><br /><br />

 

<form action='http://testbed' method=POST>

<fieldset>

<legend>Enter the image</legend>

<ol>

 

<li>

<label for='file'>File:: </label>

<input id='file' name='file' type='file' value='' size=60 maxlength=60/>

</li>

<input type='SUBMIT' class='submit' value='Submit'/>

 

</form>

 

</body>

</html>

 

I've got a bit further.

 

I've added enctype="multipart/form-data" to

<form action='http://yotspace/testbed' method=POST enctype="multipart/form-data">

 

and then looked in $_FILE and got this

 

    echo "Upload: " . $_FILES["file"]["name"] . "<br />";

    echo "Type: " . $_FILES["file"]["type"] . "<br />";

    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

    echo "Stored in: " . $_FILES["file"]["tmp_name"]."<br />";

 

It's returning

 

Upload: MissSilver.jpg

Type: image/jpeg

Size: 17.546875 Kb

Stored in: /tmp/phpeJIigI

 

I'm working on it!!!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.