2017-03-18 113 views
0
public function store($location){ 
if($this->zip->open($location, file_exists($location) ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE)){ 
foreach($this->files as $file){ 
$this->count++; 
$this->image_name ="OrderImg".$this->count.".png"; 
$this->set = str_replace('data:image/png;base64,', '', $file); 
$this->set = str_replace(' ', '+', $file); 
$this->zip->addFile($this->image_name, base64_decode($file)); 
} 
$this->zip->close(); 
} 
} 

怎麼我的base64解碼我的畫布的數據,放在我的zip文件,我不能讓在這裏工作,我的意思是讓我的畫布數據解碼使用Base64和zip它在一起。解碼Base64和傳遞到壓縮文件

壓縮文件didt創建,我不知道爲什麼。

+0

問題是什麼? – axiac

+0

壓縮文件didt創建,我不知道爲什麼。 –

+0

在功能之前刪除公共,並檢查它是否可用並啓用[錯誤報告](http://stackoverflow.com/q/845021/5914775)。 –

回答

1

試試這個:

public function store($location){ 
if($this->zip->open($location, file_exists($location) ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE)){ 
foreach($this->files as $file){ 
$this->count++; 
$this->image_name ="OrderImg".$this->count.".png"; 
$file_encoded = base64_encode($file); 
$this->zip->addFromString($this->image_name, base64_decode($file_encoded)); 
} 
$this->zip->close(); 
} 
} 

即使未解碼的,你也可以將其添加到壓縮爲這樣的映像文件:

$this->zip->addFromString($this->image_name,$file_encoded); 
+1

謝謝,我收到了zip,但是png圖像是空的,我想我可以修復它,非常感謝你。 – user3233074

0

我可能會晚點黨,但這樣的事情你可以試試:

public function store($location) 
{ 
    if($this->zip->open($location, file_exists($location) ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE)) 
    { 
     foreach($this->files as $file) // assuming you have file **array of base64 encoded images** here 
     { 
     $this->count++; 
     $this->image_name ="OrderImg".$this->count.".png"; 
     $this->set = str_replace('data:image/png;base64,', '', $file); 
     $this->set = str_replace(' ', '+', $file); 
     $this->zip->addFromString($this->image_name, base64_decode($this->set));// assuming you have base64 encoded string here obtained for $file 
     } 
     $this->zip->close(); 
    } 
} 

爲你添加嘗試使用base64編碼字符串,你必須使用addFromString(),而在addFile()

爲addfile:

bool ZipArchive::addFile (string $filename [, string $localname = NULL [, int $start = 0 [, int $length = 0 ]]]) 

或者乾脆

bool ZipArchive::addFile (string $file_name_till_fullpath, string $name_you_want_inarchive) 

和addFromString:

bool ZipArchive::addFromString (string $localname , string $contents)