Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access zip files in PHP code
    primarykey
    data
    text
    <p>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.</p> <pre><code>&lt;soap:Body&gt; &lt;AddFileToProject xmlns="http://tempuri.org/"&gt; &lt;Ticket&gt;string&lt;/Ticket&gt; &lt;ProjectID&gt;string&lt;/ProjectID&gt; &lt;Filename&gt;string&lt;/Filename&gt; &lt;FileData&gt;base64Binary&lt;/FileData&gt; &lt;SourceLanguageID&gt;string&lt;/SourceLanguageID&gt; &lt;TargetLanguageIDs&gt; &lt;string&gt;string&lt;/string&gt; &lt;string&gt;string&lt;/string&gt; &lt;/TargetLanguageIDs&gt; &lt;Metadata&gt; &lt;Meta Name="string" Value="string" /&gt; &lt;Meta Name="string" Value="string" /&gt; &lt;/Metadata&gt; &lt;IsReferenceMaterial&gt;boolean&lt;/IsReferenceMaterial&gt; &lt;/AddFileToProject&gt; &lt;/soap:Body&gt; </code></pre> <p>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.</p> <p>I have tried this:</p> <pre><code> $zipFile = 'C:/xampp/htdocs/drupalTheme/Content_4_2.zip'; $zip = zip_open($zipFile); $addFile = $ServicesLink-&gt;AddFileToProject(array('Ticket'=&gt;$ticket,'ProjectID'=&gt;$projectID,'Filename'=&gt;$fileName,'FileData'=&gt; $zip, 'SourceLanguageID'=&gt; $srcLang, 'TargetLanguageIDs'=&gt; $finalTarArray,'Metadata'=&gt; null,'IsReferenceMaterial'=&gt;false)); </code></pre> <p>and this appraoch </p> <pre><code> $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=&gt;$val) { $byteArr[$key] = ord($val); } $addFile = $ServicesLink-&gt;AddFileToProject(array('Ticket'=&gt;$ticket,'ProjectID'=&gt;$projectID,'Filename'=&gt;$fileName,'FileData'=&gt; $byteArr, 'SourceLanguageID'=&gt; $srcLang, 'TargetLanguageIDs'=&gt; $finalTarArray,'Metadata'=&gt; null,'IsReferenceMaterial'=&gt;false)); </code></pre> <p>Both result in corrupt zip files sent over.</p> <p>Would like to have your views on the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload