Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4584056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:18:05+00:00 2026-05-21T21:18:05+00:00

Total newbie here, please bear with me. Building a very small personal app that

  • 0

Total newbie here, please bear with me.

Building a very small personal app that uploads some images and info. I can’t figure out why the following PHP/MySQL doesn’t add the last insert in the query ($file_data) to my DB’s longblob field.

All the other fields in the query insert fine, meaning I tested them one at a time, adding to the query, until I got to the last and then the insert fails. I am able to echo $file_data before the insert and see that the data is there, I’ve also found that hardcoding a string value for $file_data (i.e $file_data="this will insert") inserts fine… which is frustrating.

So my guesses are there’s an error in the reading of the file ($fp fread etc) or that my longblob is setup wrong. File sizes are <16kb, so I’m sure it’s not a php.ini issue either.

Any ideas? Thanks.

$boxtype=$_POST['type'];
$title=$_POST['title'];

if(isset($_POST['submit']) && $_FILES['imgfile']['size'] > 0)
{

    $filename = $_FILES['imgfile']['name'];
    $tmpName = $_FILES['imgfile']['tmp_name'];
    $file_size = $_FILES['imgfile']['size'];
    $mime_type = $_FILES['imgfile']['type'];        

    $fp = fopen($tmpName, 'r');
    $file_data = fread($fp, filesize($tmpName));
    fclose($fp);

    $query = "INSERT INTO table 
         (boxtype,title,filename,mime_type,file_size,file_data) 
         VALUES 
         ('$boxtype','$title','$filename','$mime_type','$file_size','$file_data')
         ";

    $db = db_connect(); 
    $result = $db->query($query) or die('Error, query failed');

    if ($result) 
    {
       echo "<br>Success<br>";
    }
}
else die("No Content");

MySQL Table:

CREATE TABLE `port` (
  `id` int(2) unsigned zerofill NOT NULL AUTO_INCREMENT,
  `boxtype` tinytext COLLATE latin1_general_ci NOT NULL,
  `title` varchar(40) CHARACTER SET latin1 NOT NULL,
  `filename` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `mime_type` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `file_size` int(11) NOT NULL,
  `file_data` longblob NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:18:06+00:00Added an answer on May 21, 2026 at 9:18 pm

    Because its a binary, it probably contains values which means its probably throwing a wobble

    Try using addslashes on the file_data variable, so it can save it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A total newbie question, so please bear with me here ;) When a key
Ok, total Cucumber newbie here so please be gentle. As a learning Ruby/Cucumber/MongoDB endeavor
I am a total Groovy newbie. I saw the following code here . def
I'm a total newbie, but I was writing a little program that worked on
I'm a total amateur writing a small App to track to changes in folders.
Total newbie here, regarding sqlite, so don't flame too hard :) I have a
Total newbie question here; I apologize in advance. Suppose I have a daemon written
Total newbie to XPath and Java here. What I'm attempting to do is something
total newbie here. i was trying to replace a character in char * but
Ruby Newbie here, I understand that everything is an object in Ruby, one thing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.