uploading pictures to Mysql with PHP.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Grimmerson
    New Member
    • Apr 2012
    • 5

    #1

    uploading pictures to Mysql with PHP.

    I have a piece of code that isn't working. I'm trying to upload a few pictures to my database code is as follows:

    Upload Form:

    Code:
    <input type="hidden" name="supplier_number" value="<? echo ''.$_REQUEST["supplier_name"].'' ?>" />
    <tr>
    <td>Picture 1:
    <td><input type="file" name="image1[]" />
    <tr>
    <td>Picture 2:
    <td><input type="file" name="image2[]" />
    <tr>
    <td>Picture 3:
    <td><input type="file" name="image3[]" />
    <tr>
    <td>Picture 4:
    <td><input type="file" name="image4[]" />
    <tr>
    <td colspan="2"><center><input type="submit" value="Add Pictures" name="submit" /></center>
    And the code to process it is:

    Code:
    	$image1 = chunk_split(base64_encode(file_get_contents($_FILES["image1"]['tmp_name'])));
    	$image2 = chunk_split(base64_encode(file_get_contents($_FILES["image2"]['tmp_name'])));
    	$image3 = chunk_split(base64_encode(file_get_contents($_FILES["image3"]['tmp_name'])));
    	$image4 = chunk_split(base64_encode(file_get_contents($_FILES["image4"]['tmp_name'])));
    	$query = "UPDATE producthold SET image1 = '$image1', image2 = '$image2', image3 = '$image3', image4 = '$image4' WHERE supplier_number = $_REQUEST[supplier_name]";
    	$result = mysql_query($query);
    Everytime I try and use the code I get the error:

    Warning: file_get_conten ts() [function.file-get-contents]: Filename cannot be empty
    I'm sure its a minor mistake but I just can't figure it out (still a touch new at writing PHP).
    Last edited by Dormilich; Jun 8 '12, 07:03 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you define the input fields as array, so the access would be $_FILES["image1"][0]['tmp_name'].

    besides that, you can save the images as binary data in MySQL.

    Comment

    Working...