login about faq

hi, Greetings every one..

in my project/script, i need to create a zip file and write zip to memory (instead of file) using WriteToMemory function..

but the problem is i can't save the memory zip date to file :(

here is the related code:

$success = $objZip->WriteToMemory($objByte);
if ($success != true)
{
    exit('Zip Write error!');
}

$strZipData =  $objByte->to_s();
$intZipSize = $objByte->getSize();
header('Content-Disposition: attachment; filename="Sample.zip"');
//header("Content-type: application/zip";
header('Content-Transfer-Encoding: binary');
header("Content-length: " . $intZipSize);  
echo $strZipData;

but it only write a 5bytes string file :( and in that file it contains only:

PK

i think i have give enough information for you guys to find out the issue..

so, any help would be appreciated :)

best regards

asked Sep 21 '12 at 07:15

mAlam's gravatar image

mAlam
991215


12next page »

Thanks mAlam,

Here are new builds that should work now:

(all for Linux 64-bit)

PHP v5.2.17: http://www.chilkatsoft.com/preRelease/chilkat-9.3.2-php-5.2.17-x86_64-linux.tar.gz

PHP v5.3.*: http://www.chilkatsoft.com/preRelease/chilkat-9.3.2-php-5.3-x86_64-linux.tar.gz

PHP v5.4.*: http://www.chilkatsoft.com/preRelease/chilkat-9.3.2-php-5.4-x86_64-linux.tar.gz

Your original code using "$objByte->to_s()" should work. You may also use either "$objByte->getData()" or "$objByte->getBytes()", all of which return the data in exactly the same way.

PHP is one of the only languages where the string primitive type is really just a sequence of bytes, not necessarily null terminated, and may even contain null bytes within. Normally, one would never handle binary data as if it were a "string" because in virtually all other programming languages, the difference between a "string" and "binary data" is that it's implied that the bytes in a string are interpreted according to a character encoding, such as utf-8, utf-16, iso-8859-1, etc.

link

answered Sep 24 '12 at 15:36

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

dear sir, i have update my server php to php 5.3 download your updated version 9.3.2 (not above link) links from your site download page..

but still the same error :(

i tried with getData() and GetBytes() too.. but both returns same as i stated above: it returns this : "Resource id #4" (without quotation mark)

hope, will get an answer/solution from you soon :)

best regards

(Sep 27 '12 at 02:58) mAlam

While investigating this question, I noticed that the PHP Extension documentation for CkString and CkByteData was missing, so I updated the online reference documentation:

http://www.chilkatsoft.com/refdoc/phpCkByteDataRef.html

and

http://www.chilkatsoft.com/refdoc/phpExtCkStringRef.html

The $objByte->to_s() method is going to interpret the bytes according to the ANSI character encoding, so it's not something that should be called if the bytes do not represent actual character data, which is the case here.

Instead, try calling $objByte->getBytes() to return the unmodified bytes.

link

answered Sep 21 '12 at 12:48

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

thanks a lot for your reply sir..

but for your information, i did try that (getBytes()) function .. but that's didn't seems to work.. it returns this : "Resource id #4" (without quotation mark)

so, would you please recheck and give me a working solution sir? please?

and a note, sir, i set this forum notification settings to send me a email instantly whenever anything added to my post/question, but it doesn't send me any email, and i just visit this post and see you already replied 13hours ago :(

once again thanks for your help/trying..

waiting to here again from you

best regards

(Sep 22 '12 at 02:48) mAlam

hello? any update please?

link

answered Sep 22 '12 at 23:38

mAlam's gravatar image

mAlam
991215

Please let me know what operating system and whether it's 32-bit or 64-bit so I can provide a new build for testing..

link

answered Sep 24 '12 at 11:20

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

thanks for your reply..

sir, for your kind information, my hosting server is linux x64

please sir, leave a reply asap

take care

may Allah bless you

have a nice day

bye bye

(Sep 24 '12 at 12:21) mAlam

I tested with the following PHP script, and the .zip file is correctly written:

$objByte = new CkByteData();
$success = $zip->WriteToMemory($objByte);
if ($success != true) {
    print $zip->lastErrorText() . "n";
    exit;
}
$zipFileImage = $objByte->getData();
$fp = fopen("out.zip","w");
fwrite($fp,$zipFileImage);

Therefore, I know that $objByte->getData() is returning the correct bytes.

link

answered Sep 27 '12 at 09:14

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

once again.. thanks a lot for your reply

sir, i did gave you my full source code (php).. and i don't think there is any issue in my code..

so, would you please recheck my code.. and once again.. i don't want. to save the zipImage to file, i need to provide to user as a download (attachment header)

so, i uploaded my code again, and i think it will also run on your server too..so, would you please check again..

PHP ZIP Source

best regards

link

answered Sep 27 '12 at 12:39

mAlam's gravatar image

mAlam
991215

hello? sir? i m still waiting.. for your kind reply..

would you please update me .. and give me a solution.. .. :) ? please?

best regards

link

answered Oct 01 '12 at 12:02

mAlam's gravatar image

mAlam
991215

I have shown that the new build emits the exact bytes of the zip archive produced by WriteToMemory method. Here it is:

$objByte = new CkByteData();
$success = $zip->WriteToMemory($objByte);
if ($success != true) {
    print $zip->lastErrorText() . "n";
    exit;
}
$zipFileImage = $objByte->getData();
$fp = fopen("out.zip","w");
fwrite($fp,$zipFileImage);

If you test this code in a simple PHP script, you can verify that it produces a file that is a valid zip archive.

Given that this works, the only remaining task is to form a valid HTTP response. HTTP responses are MIME, so you want to send a MIME header that correctly specifies the content, and then emit the bytes of the zip archive. The PHP task of sending the HTTP response only involves Chilkat for the emitting of the binary Zip archive bytes. I've proven that $objByte->getData() emits the bytes correctly. The task of emitting the correct HTTP response header via PHP is not a Chilkat Zip issue. You should be able to find more information on the web regarding this..

link

answered Oct 01 '12 at 13:03

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

based on your reply, i have tried this:

file_put_contents('test.zip', $strZipData);

but php show me following error:

file_put_contents(): supplied resource is not a valid stream resource

so, i m really confused is really your object return valid zip data :(

and for your kind information, in my last post, i have attached my php script where mime header is still exits (few were commented), so, is that very hard for you to help me a bit.. by fixing the mime/header part?

please sir, leave a reply asap

best regards

link

answered Oct 01 '12 at 13:41

mAlam's gravatar image

mAlam
991215

and yes i just tried with following code too:

    $lfile = fopen('test.zip', 'w');
fwrite($lfile,$strZipData);
fclose($lfile);

but again php return following error:

fwrite() expects parameter 2 to be string

hope that may help you.. :)

best regards

link

answered Oct 01 '12 at 13:47

mAlam's gravatar image

mAlam
991215

I don't know what to say. I don't see any error using PHP 5.3.3 w/ Chilkat v9.3.2

(Oct 01 '12 at 14:09) chilkat ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×87
×35

Asked: Sep 21 '12 at 07:15

Seen: 5,479 times

Last updated: Oct 03 '12 at 23:59

powered by OSQA