linux web php文件,LINUX下面PHP文件转换

/**

文件转换

oscar 2011-11-25 jincan.liu@gmail.com

*/

class converter extends CWidget{

public function run($file)

{

$filesArr = array('pdf','doc','docx','xls','xlsx','ppt','pptx','txt');

//文件上传并转换

if($_FILES["file"] && $_FILES["file"]["error"] <=0 ){

$fileName = iconv('UTF-8','gb2312',$_FILES["file"]["name"]);

$types = explode('.',$fileName);

$typesIf = $types[1];

//改名为时间戳

$types[0] = time();

$fileName = $types[0].'.'.$types[1];

$filetype = $typesIf;

//限制上载类型

if(!in_array($typesIf,$filesArr)){

echo '';

}

/*

function check_is_chinese($s){

return preg_match('/[x80-xff]./', $s);

}

//检测中文文件名

if (check_is_chinese($fileName)) {

$types[0] = time();

$fileName = $types[0].'.'.$types[1];

}

*/

//更改路径

if($typesIf=='pdf'){

$path = 'converter/files/pdf/';

}else{

$path = 'converter/files/doc/';

}

if (file_exists($path . $fileName)){

echo '';

}else{

move_uploaded_file($_FILES["file"]["tmp_name"], $path.$fileName);

//var path

$docpath = '/data/oa/frontend/www/converter/files/doc/';

$pdfpath = '/data/oa/frontend/www/converter/files/pdf/';

$swfpath = '/data/oa/frontend/www/converter/files/swf/';

if (file_exists($path . $fileName))

{

//执行转换

if($typesIf=='pdf'){ //PDF 转SWF

$pdf = $fileName;

$swf = str_replace('pdf','swf',$pdf);

exec('/usr/local/wenku/swftools/bin/pdf2swf -o '.$swfpath.$swf.' -T -z -t -f '.$pdfpath.$pdf.' -s languagedir=/usr/share/xpdf/xpdf-chinese-simplified -s flashversion=9');

$path2 = $pdfpath.$pdf;

$path3 = $swfpath.$swf;

}else{ //DOC 转 PDF

$doc = $fileName;

$format = explode('.',$fileName);

$formatName = $format[0].'.pdf';

$command = 'java -jar /usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar '.$docpath.$doc.' '.$pdfpath.$formatName;

exec($command);

$path1 = $docpath.$doc;

$path2 = $pdfpath.$formatName;

if(file_exists( $pdfpath.$formatName)){

$pdf = $formatName;

$swf = str_replace('pdf','swf',$pdf);

$swfcommand = '/usr/local/wenku/swftools/bin/pdf2swf -o '.$swfpath.$swf.' -T -z -t -f '.$pdfpath.$pdf.' -s languagedir=/usr/share/xpdf/xpdf-chinese-simplified -s flashversion=9';

exec($swfcommand);

$path3 = $swfpath.$swf;

}

}

}

}

// print_r($_FILES["file"]);

$filetype = isset($filetype) ? $filetype : '';

$path1 = isset($path1) ? str_replace('/data/oa/frontend/www','',$path1) : '';

$path2 = isset($path2) ? str_replace('/data/oa/frontend/www','',$path2) : '';

$path3 = isset($path3) ? str_replace('/data/oa/frontend/www','',$path3) : '';

$reArr = array('filetype' => $filetype,'path1'=>$path1,'path2'=>$path2,'path3'=>$path3);

return $reArr;

}

}

//删除文件

public function DelFile($path,$pdfpath,$swfpath){

$pathcommand = 'rm -rf /data/oa/frontend/www'.$path;

exec($pathcommand);

$pdfpathcommand = 'rm -rf /data/oa/frontend/www'.$pdfpath;

exec($pdfpathcommand);

$swfpathcommand = 'rm -rf /data/oa/frontend/www'.$swfpath;

exec($swfpathcommand);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值