我有一组文件加载到数据库中的自动更新程序以供以后使用PHP脚本。该程序工作正常,直到文件超过10MB范围。该脚本的大概思想是它从特定位置的磁盘中提取文件,并将它们加载到数据库中。这允许我们存储源代码控制,并根据需要进行更新。PHP addslashes的失败时,文件太大
起初,我还以为我被击中根据我的初步搜索的数据库SQL的限制。但是,经过进一步测试后,它似乎是PHP特有的东西。我检查了Apache错误日志,但是我没有看到这个脚本或包含的任何错误。一旦PHP脚本到达addslashes函数,脚本似乎停止执行。 (我在每个脚本语句之间添加了回显语句)。
我希望这是简单的东西,我很想念,但在线上搜索几个小时后,找不到与addslashes相关的任何内容。
任何想法?
在此先感谢。
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!='.' && $file!='..' && $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].<br>\n";
}
header("Location: /patch/index.php?pid=".$_REQUEST['pid']);
你为什么存储10MB +文件在数据库中。 (最好是将它们存储为磁盘上的实际文件,并将*文件名*保存在数据库中。 – Amber
这不是我构建或设计的系统,而是我需要继续运行的系统。数据库存储多种版本的over数百种数字产品,它已经工作了5年多,并且随着产品文件变得越来越大而开始失败,我只是试图找到一种方法来保持它的发展,而不需要重新设计几周重新设计系统补丁。 – JPG