1

Hey Guys sorry about the bad formatting and thnks for your support. I will try to explain better this time. I have a zip file named Content_4_2.zip at location 'C:\xampp\htdocs\drupalTheme'. This zip contains 2 xml files. Now the web service method to which i want to pass this zip has the definition as follows.

<soap:Body>
    <AddFileToProject xmlns="http://tempuri.org/">
      <Ticket>string</Ticket>
      <ProjectID>string</ProjectID>
      <Filename>string</Filename>
      <FileData>base64Binary</FileData>
      <SourceLanguageID>string</SourceLanguageID>
      <TargetLanguageIDs>
        <string>string</string>
        <string>string</string>
      </TargetLanguageIDs>
      <Metadata>
        <Meta Name="string" Value="string" />
        <Meta Name="string" Value="string" />
      </Metadata>
      <IsReferenceMaterial>boolean</IsReferenceMaterial>
    </AddFileToProject>
  </soap:Body>

The FileData 'base64Binary' is the content i want to send i.e. the zip file. In Java i was able to convert the zip file into a bytearray and the web service was called sucessfully.Now i know that there is no such conversion in PHP. So my approach is 1.Get the name of the zip file from the directory 2.Pass the contents of the zip to web service.

I have tried this:

  $zipFile = 'C:/xampp/htdocs/drupalTheme/Content_4_2.zip';
  $zip = zip_open($zipFile);
  $addFile = $ServicesLink->AddFileToProject(array('Ticket'=>$ticket,'ProjectID'=>$projectID,'Filename'=>$fileName,'FileData'=> $zip, 'SourceLanguageID'=>  $srcLang, 'TargetLanguageIDs'=> $finalTarArray,'Metadata'=> null,'IsReferenceMaterial'=>false));

and this appraoch

 $zipFile = 'C:/xampp/htdocs/drupalTheme/Content_4_2.zip';
  $file = file_get_contents('./Content_4_2.zip',true);
  $byteArr = str_split($file);
  foreach ($byteArr as $key=>$val) { $byteArr[$key] = ord($val); }

  $addFile = $ServicesLink->AddFileToProject(array('Ticket'=>$ticket,'ProjectID'=>$projectID,'Filename'=>$fileName,'FileData'=> $byteArr, 'SourceLanguageID'=>  $srcLang, 'TargetLanguageIDs'=> $finalTarArray,'Metadata'=> null,'IsReferenceMaterial'=>false));

Both result in corrupt zip files sent over.

Would like to have your views on the same.

hakre
  • 193,403
  • 52
  • 435
  • 836
Angela Sim
  • 137
  • 1
  • 21
  • Welcome to SO! There are libraries available for this: Googling `drupal zip` or `php zip` should give you everything you need. – Pekka Dec 15 '11 at 13:18
  • 1
    Now that it's reformatted, I'm not sure what your question is. Do you need to unzip the zip file, or is this about somehting else? – Pekka Dec 15 '11 at 13:26
  • @Angela Sim: Your question is not entirely clear - You say _"In Java i was able to convert the zip file into a bytearray"_, which sounds like you just converted (and sent) the whole zip file. But in your test example, you try to unzip the archive first and sent the contained files. Which file(s) do you want to sent - the zip archive as a whole, or the contained files separately? – Henrik Opel Dec 15 '11 at 17:07
  • @Henrik Opek: I said i was able to do a similar operation in Java when i was working with a Java based CMS. Now i am working on Drupal6 which is in PHP ,i am trying to do the same thing. I have already created a zip file via my PHP code and it creates a zip file at the location 'C:/xampp/htdocs/drupalTheme/Content_4_2.zip'.Now i need to send that zip file over to that webservice method i have mentioned.Feel free to ask for more clarifications. – Angela Sim Dec 16 '11 at 08:29
  • @Angela Sim: Ok, I added an answer for sending the whole zip file below, using explicit base64 encoding on the content - you might want to try if this addresses your problem. – Henrik Opel Dec 16 '11 at 14:38

2 Answers2

0

Use PHP's ZIP functions: http://php.net/manual/en/ref.zip.php

This tutorial should lead to down the right path as to how to use it: http://www.timlinden.com/blog/website-development/unzip-files-with-php/

Ayman Safadi
  • 11,502
  • 1
  • 27
  • 41
0

Assuming you want to send the zip archive as a whole (i.e. without extracting it), as your second test example hints on, you might want to try skipping the 'byte array' part and just use base64_encode() to encode the file directly. Using your example code, it would look somewhat like this:

$zipFile = 'C:/xampp/htdocs/drupalTheme/Content_4_2.zip';
$fileContent = file_get_contents($zipFile, true);
$fileEncoded = base64_encode($fileContent);
$addFile = $ServicesLink->AddFileToProject(
  array(
    'Ticket'=>$ticket,
    'ProjectID'=>$projectID,
    'Filename'=>$fileName,
    'FileData'=> fileEncoded,
    'SourceLanguageID'=>  $srcLang,
    'TargetLanguageIDs'=> $finalTarArray,
    'Metadata'=> null,
    'IsReferenceMaterial'=>false
  )
);
Henrik Opel
  • 19,341
  • 1
  • 48
  • 64