1

I am using this form:

<FORM action="testimage1.php" method="post">
                 <div style="font:bold 10px arial,serif;" >Product Name*</div>
                 <input type="text" name="myuserName" maxlength="50" /><br />
                  <div style="font:bold 10px arial,serif;" >Upload a photo</div>
                 <input name="uploadimage" type="file" /></br>
                 <div style="font:bold 10px arial,serif;">Product Description:</div> <input type="text" name="product" value=""></br>
                 <input id="submit" type="submit" value="submit" /><br />
                 </form>

and in test1.php

require_once("dbconnect.inc.php");  //for database connection                   
    $db_name="thinstrokes";                                     
     $tbl_name="product";
     $db_selected=mysql_select_db("$db_name")or die("cannot select DB");
    // Connect to server and select databse.
    // username and password sent from form 
    $myusername=$_POST['myusername']; 
    $myproduct=$_POST['product'];
    $filename=$_POST['uploadimage'];

$imgData = file_get_contents($filename);
    $size = getimagesize($filename);
    $sql = "INSERT INTO product
    (productname, image_id , image_type ,image, image_size, image_name,productdesc)
    VALUES
    ('$myusername','11', '{$size['mime']}', '{$imgData}', '{$size[3]}', 
     '{$_FILES['userfile']['name']}','$productdesc')";
    $result=mysql_query($sql) or die("error in uploading/*");

and getting errors are:-

file_get_contents(DSC02945.JPG) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\thinstrokes original site\testimage1.php on line 22

Warning: getimagesize(DSC02945.JPG) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\htdocs\thinstrokes original site\testimage1.php on line 23

how can i correct it..???

5
  • 1
    enctype should be multipart/form-data Commented May 31, 2012 at 7:43
  • also check if image attribute in product table is BLOB type (otherwise the binary data can be messed up due to charset conversion) Commented May 31, 2012 at 7:51
  • why are you want to insert the image in database ....generally we store the images in a folder and store the image name in db...it will make your db clean...... Commented May 31, 2012 at 7:51
  • i am only want to add a image jpg/png not the folder Commented May 31, 2012 at 7:54
  • You need to $imgData (and everything else) through mysql_real_escape_string before putting it in a query. Commented May 31, 2012 at 8:04

2 Answers 2

3

You need enctype=multipart/form-data in your form declaration. And access the file through the $_FILES variable instead of the $_POST variable. Like:

<form action="testimage1.php" method="post" enctype="multipart/form-data">
   <input name="uploadimage" type="file" />
</form>

<?php
    $filename = $_FILES['uploadimage']['tmp_name'];   
?>
Sign up to request clarification or add additional context in comments.

1 Comment

That's a whole other problem. You file upload now succeeded, which is an answer to the current question.
-1
$imgData = file_get_contents($filename);
$size = getimagesize($filename);
mysql_connect("localhost", "$username", "$password");
mysql_select_db ("$dbname");
$sql = sprintf("INSERT INTO testblob
    (image_type, image, image_size, image_name)
    VALUES
    ('%s', '%s', '%d', '%s')",
    mysql_real_escape_string($size['mime']),
    mysql_real_escape_string($imgData),
    $size[3],
    mysql_real_escape_string($_FILES['userfile']['name'])
    );
mysql_query($sql);

1 Comment

Please explain what it was that you corrected, and what the mistake was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.