我所做的工作在以下步驟:上傳圖像正在正確的,但不能在服務器
我寫的代碼讀取MS Word文件,在它的形象。
從XML代碼中提取文件路徑後,我在本地服務器上成功上傳圖像。 xml文件示例: -
<pic:cnvpr id="0" name="Picture 4" descr="C:\Users\Administrator\Documents\tshirt\14714-yepme-s-275x340-imadpnn23zqpjqzz.jpeg"</pic:cnvpr>
當我上傳服務器上的word文件並從不同PC上的服務器上下載它時,就會出現與啓動時一樣的圖像文件。
但是現在,當我從服務器上傳文件文件時,顯示本地服務器和圖像的相同路徑未上傳的文件。
我的問題是:如何上傳服務器上的word文件圖像?
讀取XML文件的描述後,我只是複製圖像像這樣
$pattern2 = '/descr="(.*?)"\/>/';
$str = str_replace('\\', '/', $val);
copy($str,$imagepath);
換句話說,我想在服務器上的文件從我的電腦上傳的,我有一個文件的本地路徑。
這裏就是我用read_file_docx
功能爲docx
文件轉換成xml
一些分隔符的完整代碼:
if($_FILES["file"]["name"][$value]!='' && ($ext=='docx' || $ext=='doc')){
$rand=time();
$fileName=$scheduleId."_".$value."_".$rand.".doc";
$cvsId=uploadCsvForQuestion($value,$scheduleId,$fileName,$rand);
copy(
$_FILES["file"]["tmp_name"][$value],
"../question_csv/" .$fileName
); // file save in folder
//extract data from doc file
$allData=read_file_docx($_FILES["file"]["tmp_name"][$value],"r");
// explode from question
$rre=explode("^@@@^",$allData);
//print_r($allData);exit;
$pattern2 = '/descr="(.*?)"\/>/';
foreach($rre as $key=>$rrevalue){
if($key!=0){
$remaks=explode("Remarks:",$rrevalue);
$hint=explode("Exp:",$remaks[0]); //explode from hint.
$ans=explode("Ans-",$hint[0]);//explode from ans.
$option=explode("^@@^",$ans[0]);//explode from options with question.
preg_match_all($pattern2, $hint[1], $hintmatches);
// All images in hint will save in array then save in field
if(is_array($hintmatches)){
foreach($hintmatches[1] as $key=>$val){
$str = str_replace('\\', '/', $val);
if(file_exists($str)){
$imag1=rand().basename($str);
$sestination="../question_image/";
copy($str,$sestination."".$imag1);
$images_hint[]=$imag1;
}
}
if(is_array($images_hint)){
$imagesHint=implode("||",$images_hint);
$images_hint='';
}
}
foreach ($option as $keys=>$valuew) {
preg_match_all($pattern2, $valuew, $matches2);
// All images in that section like question and option will save in array then save in field
if(is_array($matches2[1])){
foreach($matches2[1] as $key=>$val){
$str = str_replace('\\', '/', $val);
if(file_exists($str)){
$imag2=rand().basename($str);
$sestination="../question_image/";
copy($str,$sestination."".$imag2);
$imagesArray[]=$imag2;
}
}
if(is_array($imagesArray)){
$imag=implode("||",$imagesArray);
$imagesArray='';
}
}
$valuew = strip_tags($valuew,"<sub><sup>");
if($keys==0){
//$str11= substr($valuew,'2'); old one
$newQuesion=explode(".",$valuew);
//
$num=0;
if($newQuesion!=''){
$hint = strip_tags($hint[1],"<sub><sup>");
$quesionId=uploadQuestion($cvsId,$value,$scheduleId,addslashes($newQuesion[1]),$hint,$imag,$imagesHint,$imagesHint,$remaks[1]);//save question
$imagesHint='';
}
}else{
uploadOption($quesionId,addslashes($valuew),$keys,$imag);//save option
}
$num++; $imag="";
}
if($ans[1]!=''){
uploadAnswer($quesionId,$ans[1]);//save answer
}
}
}
}
function read_file_docx($filename){
$striped_content = '';
$content = '';
if(!$filename || !file_exists($filename))
return false;
$zip = zip_open($filename);
if (!$zip || is_numeric($zip))
return false;
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) continue;
if (zip_entry_name($zip_entry) != "word/document.xml") continue;
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
file_put_contents('question.xml', $content);
$content2 = explode('<w:vertAlign w:val="subscript"/></w:rPr><w:t>', $content);
$pattern = "/<w:vertAlign w:val=\"subscript\"\/><\/w:rPr><w:t>(.*?)<\/w:t><\/w:r>/";
preg_match_all($pattern, $content, $matches);
$var=array_map("strip_tags_sub",$matches[1]);
foreach($content2 as $key=>$value)
{
if($key!=0){
$var1=strip_tags($var[$key]);
$content=str_replace('<w:vertAlign w:val="subscript"/></w:rPr><w:t>'.$var1."</w:t></w:r>", $var[$key],$content);
}
}
$content1 = explode('<w:vertAlign w:val="superscript"/></w:rPr><w:t>', $content);
$pattern = "/<w:vertAlign w:val=\"superscript\"\/><\/w:rPr><w:t>(.*?)<\/w:t><\/w:r>/";
preg_match_all($pattern, $content, $matchesa);
$var1=array_map("strip_tags_sup",$matchesa[1]);
foreach($content1 as $key=>$value)
{
if($key!=0){
$varq=strip_tags($var1[$key]);
$content=str_replace('<w:vertAlign w:val="superscript"/></w:rPr><w:t>'.$varq."</w:t></w:r>", $var1[$key],$content);
}
}
$content = str_replace('</w:r></w:p>', " ", $content);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$allData = strip_tags($content,'<pic:cNvPr><sub><sup>');
$allData = str_replace('(Q', "^@@@^", $allData);//saperate from question
$allData = str_replace('1).', "^@@^", $allData);//saperate from option
$allData = str_replace('2).', "^@@^", $allData);//saperate from option
$allData = str_replace('3).', "^@@^", $allData);//saperate from option
$allData = str_replace('4).', "^@@^", $allData);//saperate from option
$allData = str_replace('5).', "^@@^", $allData);//saperate from option
$allData = str_replace('6).', "^@@^", $allData);//saperate from option
return $allData ;
}
您將需要顯示您正在使用的代碼。 – 2014-09-28 16:13:55
你可以發佈你的代碼嗎? – 2014-10-06 06:55:47
我用完整的代碼編輯了這個問題 – vinod 2014-10-06 07:43:35