2014-10-01 54 views
0

成功讀取msword文件的圖像後,顯示它。從word文件中提取圖像後在系統上創建副本

現在我想複製那些圖像。圖像複製功能工作正常,但圖像中crrupted格式

代碼是

$document = 'wordfile.docx'; 
readZippedImages($document); 
function readZippedImages($filename) { 
$zip = new ZipArchive; 
if (true === $zip->open($filename)) { 
for ($i=0; $i<$zip->numFiles;$i++) { 
$zip_element = $zip->statIndex($i); 
if(preg_match("([^\s]+(\.(?i)(jpg|jpeg|png|gif|bmp))$)",$zip_element['name'])) { 
saveImage('http://localhost/readfileimage/display.php?filename=".$filename."&index=".$i."'); 
echo "<image src='display.php?filename=".$filename."&index=".$i."' /><hr />"; 
} 
} 
} 
} 
function saveImage($path) 
{ 
copy($path, rand().'-flower.jpg'); 
}  

這裏是文件Display.php的的代碼

/*Tell the browser that we want to display an image*/ 
     header('Content-Type: image/jpeg'); 
    /*Create a new ZIP archive object*/ 
     $zip = new ZipArchive; 

     /*Open the received archive file*/ 
     if (true === $zip->open($_GET['filename'])) { 

    //$zip->open($path, ZIPARCHIVE::CREATE); 
    /*Get the content of the specified index of ZIP archive*/ 
      echo $zip->getFromIndex($_GET['index']); 
     } 

     $zip->close(); 

回答

0

請試試這個

function saveImage($path) { 
    $imageUrl = $path; 
    $contents = file_get_contents(trim($imageUrl)); 
    if ($contents) { 
    file_put_contents('/path/to/save/flower.jpg', $contents); 
    } 
}  
+1

試過但沒有用。 – vinod 2014-10-01 09:52:09

+0

使用這個問題有什麼問題? – 2014-10-02 04:16:53

+0

你有沒有面臨同樣的問題? – 2014-10-02 04:17:30