PHP addslashes failing when files too large
<p>I have a set of PHP scripts that load files into a database for an auto-updater program to use later.  The program works fine until a file exceeds the 10MB range.  The rough idea of the script is that it pulls files from disk in a specific location, and loads them into the database.  This allows us to store in source control, and update in sets as needed.</p>

<p>Initially, I thought that I was hitting a limit on the database SQL based on my initial searches.  However, after further testing, it seems to be something PHP specific.  I checked the Apache error log, but I did not see any errors for this script or the includes. Once the PHP script reaches the addslashes function, the script seems to stop executing.  (I added echo statements between each script statement.)</p>

<p>I'm hoping that it is something simple that I am missing, but I couldn't find anything related to addslashes failing after several hours of searching online.</p>

<p>Any ideas?</p>

<p>Thanks in advance.</p>

<pre><code>mysql_connect('localhost', '****', '****') or die('Could not connect to the database');
mysql_select_db('****') or die('Could not select database');

function get_filelist($path)
{
        return get_filelist_recursive("/build/".$path);
}
function get_filelist_recursive($path)
{
        $i = 0;
        $list = array();
        if( !is_dir($path) )
                return get_filedetails($path);

        if ($handle = opendir($path))
        {
                while (false !== ($file = readdir($handle)))
                {
                        if($file!='.' &amp;&amp; $file!='..' &amp;&amp; $file[0]!='.')
                        {
                                if( is_dir($path.'/'.$file) )
                                {
                                        $list = $list + get_filelist_recursive($path.'/'.$file);
                                }
                                else
                                {
                                        $list = $list + get_filedetails($path.'/'.$file);
                                }
                        }
                }
                closedir($handle);
                return $list;
        }
}
function get_filedetails($path)
{
        $item = array();
        $details = array();
        $details[0] = filesize($path);
        $details[1] = sha1_file($path);
        $item[$path] = $details;
        return $item;
}

$productset = mysql_query("select * from product where status is null and id=".$_REQUEST['pid']);
$prow = mysql_fetch_assoc($productset);

$folder = "product/".$prow['name'];
$fileset = get_filelist($folder);
while (list($key, $val) = each($fileset))
{
    $fh = fopen($key, 'rb') or die("Cannot open file");
    $data = fread($fh,$val[0]);
    $data = addslashes($data);
    fclose($fh);
    $filename = substr( $key, strlen($folder) + 1 );
    $query = "insert into file(name,size,hash,data,manifest_id) values('".$filename."','".$val[0]."','".$val[1]."','".$data."','".$prow['manifest_id']."')";
    $retins = mysql_query($query);
    if( $retins == false )
        echo "BUILD FAILED: $key, $val[0] $val[1].&lt;br&gt;\n";
}

header("Location: /patch/index.php?pid=".$_REQUEST['pid']);
</code></pre>
