1

I want to load a file(docx e.g.) from a REST API and store the content directly in a php variable, without any downloads to the file system. I know I could save the file at a certain location and access it, but I want to skip this step.

Is this possible? So far I have a "letter salad" after the REST request like this:

(‡E×à•“B)ÁëÒæØšB¯Š4k‹H!“øßWûIHœìRWä²à•æym1«Ë'kŠQ£«ØY¹d8‰J»MÅ~ß^/¾²"’pJtP±=Dv¹þt²ºÝ{ˆEªv±b["Áy”[°"–èÁ¥•ƒ”>† ÷BÞ‹ ðóåò—è-¨a°õêÔbg¨øþ”^w&LdÅU·±Éª˜ðÞh)(­ó§^¤,ú„2U¶{âVûxš60~0¡Yy; ¯û™Z´‚âFú!lÚÅ1(®Pîlª,ßÇðÄºÖÆú†æJˆ1õÜšr\±B»Áÿ‡ÜEBûÇ®   ìM@ÏŽÖ¡ i{øf/"í Äÿ߉Ž;D© ‡@OžTx„»_Ù,žÁ'EjDrH9¾=)NerÈ“ mCÈ 0g+´WŽ•OeH˜TÚ‚PŽ¿$^™tà™ùç–ßü„³œ¿ÏÌÏpþ™ù]›>pÿ3äÏîÊwrôèI    èstÜÉxJ#tÏãÿ-æ½È´³LÒmþáÌÃL×T/ü¬‰dLLè£ÏýÍz ›·ðú/ÿ)

which represents the file, but I cant access the content of the file.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
Plemo
  • 51
  • 5
  • can you please show the code for how to retrieve your "letter salad" from the REST request ? also, what file type are you expecting this to be? – devlin carnate Nov 03 '15 at 15:33
  • The type is docx. I used curl, and got this letter salad in the curl response `$service_url = $url; $curl = curl_init($service_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $curl_response = curl_exec($curl);` the url is like this [link](http://www.php-dummies.de/run/Tutorials/Praxis/File%20Download/0/2.html), it leads to a direct download – Plemo Nov 03 '15 at 16:14
  • "but I cant access the content of the file" — What are you doing to try to access the content? Are you trying to treat it as plain text? It isn't plain text, so you can't do that. – Quentin Nov 03 '15 at 16:20
  • I agree with @Quentin. This is what 'Having access to the file' looks like. Now you have access to the file, what do you want to do with it? – Evert Nov 03 '15 at 16:22
  • In my example it is about the LMS moodle, i have a REST request, where i can download a docx file into my file system, the url looks like this: http://localhost/webservice/pluginfile.php/246/mod_resource/content/1/FILE.docx?forcedownload=1&token=f4439015fccce6bcdd4aa591814d5473 I don't know if it is possible but my idea was to parse the "letter salad" into xml or any format wherewith i can get the plain text of my original docx document. Does this make it clearer? – Plemo Nov 03 '15 at 16:37
  • @Plemo — It confirms I was right about it being a duplicate. – Quentin Nov 03 '15 at 16:40
  • @Quentin Are you sure? The docx file in the question you are referring to already exists at the file system. My question is how to skip exactly that part. My docx file is located somewhere else, I want to get its content **WITHOUT** having to download the file into my file system. My "letter salad" is the result, more precisely, the response body of a download link for a docx file. – Plemo Nov 03 '15 at 16:51
  • There are several solutions which get you 95% of the way there. You could try filling in the remaining 5% yourself. – Quentin Nov 03 '15 at 16:57
  • How? I have to write the name and the path of the document in order to receive the content, but in my case it is a URL. I can't treat the URL as a path... Please bear with me. – Plemo Nov 03 '15 at 17:37
  • @Quentin, I am sorry, I have to bother you again. I still have no idea how to solve my problem – Plemo Nov 04 '15 at 15:28

0 Answers0