简体   繁体   中英

Sending or linking files between a JavaScript/HTML front-end and a PHP/MySQL back-end

I'm looking to create a "file generator", for want of a better word. However, I'm open to creative suggestions as to how to do this.

Essentially what I want is this:

  • Input: User fills out a few text-boxes
  • Process: System stores text information in a DB, formats the text in to some nice boxes with headers etc.
  • Output: System makes formatted text available to users.. somehow

However, what I'll settle for, is something like this:

  • Input: User fills out a few text-boxes.
  • Process: System stores text information in a DB for future edit/retrieve actions
  • Output: System generates a PDF file for the user to download

That sounds fairly straightforward. In PHP alone, it would be.

Unfortunately, I'm working with a school Virtual Learning Environment. I have to create Netvibes UWA Format widgets (in JavaScript) and use AJAX (AHAH, strictly speaking) calls to communicate with the PHP.

Presuming I thus can't create the documents I want with JavaScript (can't appear to find any half-decent PDF libraries, and I don't want to be limited to one file format anyway), is there any way I can make a call to my PHP script then have it send a file back for the JavaScript code to in some way deal with?

I'm not sure I can make the PHP script directories accessible to all users via the VLE, so simply sending a link back after creating the file with PHP won't work.

Thanks in advance,

To expand on my comment;

  1. send the php-created file back as the ajax response
  2. btoa the data to make a base64 string (alternatively do this server side and send this back, bigger internet usage but I'm not sure how well XMLHttpRequest handles binary data)
  3. Append this string to 'data:application/octet-stream;base64,' to get a data URI
  4. Set window.location.href (or some iframe) to this URI, page won't change as it will do download behaviour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM