exec("cd ".$pdfimg_path);
$temp = exec("cd ".$pdfimg_path."&& ./pdf2img -f 1 -w 150 -h 200 ".$convert_path.$file_name.".pdf ".$convert_path.$file_name.".jpg");
//生成swf
$temp = exec($swftools_path." -f -T 9 -t ".$convert_path.$file_name.".pdf -o ".$convert_path.$file_name.".swf");
if(strrpos($temp, 'NOTICE') === false){//第一种那个方式转换失败
//第二种转换方式
$temp = exec($swftools_path." -f -T 9 -t -s poly2bitmap ".$convert_path.$file_name.".pdf -o ".$convert_path.$file_name.".swf");
}
echo "1->".$item['aid'].' : ';print_r($temp);echo "\n";
//获取pdf总页数
$pagenum = getPageTotal($convert_path.$file_name.".pdf");
if(!file_exists($convert_path.$file_name.".jpg")){//jpg
exec($mv_path."mv ".$convert_path.$file_name."0001.jpg ".$convert_path.$file_name.".jpg");
}
//将swf,jpg和源文件拷贝到文件服务器
/*上传swf*/
$client->putObject(array(
'Bucket' => 'bucket-wenku',
'Key' => $file_name.'.swf',
'Content' => fopen($convert_path.$file_name.'.swf', 'r'),
'ContentLength' => filesize($convert_path.$file_name.'.swf'),
));
/*上传jpg*/
$client->putObject(array(
'Bucket' => 'bucket-wenku',
'Key' => $file_name.'.jpg',
'Content' => fopen($convert_path.$file_name.'.jpg', 'r'),
'ContentLength' => filesize($convert_path.$file_name.'.jpg'),
));
/*上传源文件*/
$client->putObject(array(
'Bucket' => 'bucket-wenku',
'Key' => $local_file_name,
'Content' => fopen($convert_path.$local_file_name, 'r'),
'ContentLength' => filesize($convert_path.$local_file_name),
));
//写入数据库
//$onlineviewurl = '/swf/'.$file_name.'.swf';
$onlineviewurl = '/load.php?file='.$file_name.'.swf';
$sql = "update t_addonbook set onlineviewurl='$onlineviewurl',wwk=1,pagenumber=$pagenum where aid=$item[aid]";
$db->query($sql);
//$litpic = '/swf/'.$file_name.'.jpg';
$litpic = '/load.php?file='.$file_name.'.jpg';
$sql = "update t_archives set litpic='$litpic' where id=$item[aid]";
$db->query($sql);
//删除文件
exec("rm -rf ".$convert_path.$file_name."*");
//删除上传目录文件
exec("rm -rf ".$upload_path.$local_file_name);
}else{
//复制文件失败
}
}else{
//写入错误日志
}
sleep(1);
}
echo "5\n";
sleep(5);
}
/**
* 获取PDF的页数
*/
function getPageTotal($path){
// 打开文件
if (!$fp = @fopen($path,"r")) {
return false;
}
else {
$max=0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)){
preg_match('/[0-9]+/',$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
}
}
fclose($fp);
// 返回页数
return $max;
}
}
function isUTF8($str)
{
$str1 = file_get_contents($str);
$code = chkCode($str1);
if($code=='UTF-8'){
return TRUE;
}else{
return FALSE;
}
}
function chkCode($string){
$code = array('UTF-8','GBK','GB18030','GB2312');
foreach($code as $c){
if( $string === iconv('UTF-8', $c, iconv($c, 'UTF-8', $string))){
return $c;
}
}
return "no";
}
?>
(责任编辑:最模板) |