sending and receiving files with PHP jQuery - php

How can I send and receive files live like in yahoo chat? i.e if I send the file than the user on the other end will only get that file if he click on the accept button and if he click deny than the file should not upload and should be deleted from the server... I want to do that via PHP jQuery $.ajax().

This is a rather complicated question, and not easily addressed. Here are a couple things:
You'll want a way to identify conversations. You wouldn't want your file-request getting intercepted by a completely different set of people.
You'll probably want to invoke some form of long-polling that will send a request to the server, who in turn will send a request (link) to the other user, who, when clicks the link, the server will return the first request back to you, initializing your upload.
You can use the jQuery Plugin Uploadify for the asynchronous uploads, and late-initialization from a server-response.
You may also want to keep a database table to list all of the file shared by any particular conversation. This would be queries to find out if new files need to be listed in the users windows.

Related

How to force CSV download when it reaches the client-side? (PHP)

I am trying to serve up a CSV file as the response to a get request.
If I go onto Dev tools -> Network I can see the CSV values in the response preview, and if I double click that it will download the file. However I can't seem to get it to download automatically.
I have messed around with every type of header I can think of.
Any ideas?
Yes, It seems you can't get file downloads from ajax requests (Thanks to Quentin for the linked answer in the comments), at least not easily anyway.
This is because there is a subtle separation between the user and the browser. Ajax is triggered by the browser so the file is returned to the browser not the user.
A form submit on the other hand is triggered by the user and so the file is returned to the user (automatically downloading).
So in order to fix this I changed to a form with a post method with hidden inputs and it now works a treat.
Thanks all.

Can a HTTP PUT request specify additional information as well as the file data?

I wish to send some small files (crash log files) from my application to a web server. libCurl or WinINet seem the most obvious options, to send a simple HTTP PUT request. However is it possible to inform the server any more information about the file, like the file-name or user name, or does a PUT request by definition simply send the file contents and nothing else?
POST allows much more information but also seems far more complex, having to send content types and fake form submission, etc... if POST is the only option to do what I want what would minimal code to send a file look like, and what would my server code look like to receive it?

Force download PDF created by TCPDF, after Ajax post submit

My application allow the users to complete a form, and send it with an Ajax post call.
The form si sent to the TCPDF class that create a PDF file.
The class has the method "->output(...)" that permit to save the file into web server, send it to the browser, ecc...
my goal is, after the form submit, create the PDF file, and force the user to download it (with no refreshing).
The method doesn't work with ajax calls.
The only solution I've found is create the file, seve it into web server, and than redirect the user to the location of the file to the web server; but it isn't a nice solution, I need to force the download (auto starting).
I've read others similar solution on the forum, but thay aren't good form
Any suggestions?
$pdf->Output("filename.pdf",'D');
Try
$pdf->Output("filename.pdf",'FD');
This will suggest client if he wants to save or open file.

Bypassing the AJAX Same-Origin Policy - A particular case

While I was trying to refresh page contents dynamically using Ajax/JQuery, I have learned about the S-O-P issue and restrictions, however I was wondering if there could be a way to solve my little problem.
To make it easier to understand I will first explain the workflow.
I do receive web pages via email, that is HTML emails. The web pages contain HTML forms in such a way, once the form is complete it is sent to the proper web server (php) to store data.
I mostly use Outlook 2007 as my email client (don't say anything here, I know!!!), but for some security restrictions, IFRAMES are disabled when "opening" the email. I have circumvented this problem using a VBA script that copies the whole page content, saves it on the filesystem as a stand-alone web page and loads into the browser (Firefox).
Once the page is loaded into the browser, the address bar shows a local/filesystem URL, such as
file:///C:/Users/Bob/Desktop/outlookpage.htm
Till here no problem, works fine; now the problem:
I wished to dynamic update page contents using Ajax, using jQuery.load, however that's where the S-O-P comes in. The PHP page being loaded to dynamically update the web page is seen as running on another domain, thus being blocked.
I was wondering how to circumvent this.
That's not going to work because in order to bypass the same origin policy, you would need to use a proxy on the same domain, which will then communicate to the page that's handling the data on a different domain. There's no way to generate a proxy script on another user's computer (or at least, there SHOULDN'T BE A WAY). I would either just post the form normally, which will open the user's default browser, or provide a link to an online form in the email. The link should be provided anyway, in case their email client doesn't support HTML email.

How do I save specific responses from webservers in my local computer

I have been asked to write to save the data in some secure place after certain task is completed by a client.
Here my client has alot of staffs who makes data entry in online forms provided by some different vendors. After some steps the entered data generates some results. i.e after submitting the web form. Now he wants the generated results to be saved either in local computer or in some online server.
Can it be done by:
1.) Creating a local web server which sits in between the users and the online main third party server and record all the generated results?
2.) Creating a browser extension [m thinking about firefox] and forcing users to navigate via the specific browser and record all the generated results?
**I am pretty sure that second method can work as firebug is doing that only need to add some functionality to save the data.
any idea will be appreciated.
Sorry for mis-leading guys. To make more clear here are some more explanation.
a.) I am writing application to one of my client who has many staffs who enters data in abc.com website.
b.) User submits the data to abc.com.
c.) the website abc.com produces or generates some result as per input data and sends back to user.
d.) Now I need a system which will be inbetween the staffs/user and abc.com website and track the responses of abc.com and save it to some location automatically.
e.) Currently the data entry user will manually save the result to his local computer and if he/she forgets to save then we miss the result so want to do it automatically so that we wont be missing any single result.
A local webserver wouldn't really help so much because of crossdomain issues, unless you wanna go with something as JSONP. In that case, you might wanna use a signed java applet, which (assuming the user accepts the certificate) has any access an installed Java app would have, so it could potentially bind a port and server as HTTP server (I'm not sure how well this works on linux or unix).
Another idea would be to use Flash's local shared objects. Depends on how much data you want to save. You may need to make the Flash visible, so the user can see the dialog for allowing the data to be saved. You can communicate from JavaScript to Flash using ExternalInterface.
Yet the most simple thing is to give the user a permanent cookie, and save the data associated with that cookie on a web server.
greetz
back2dos
Take a look at HTML5 local storage if you don't need a lot of data to be stored or you can use local databases, see http://blog.darkcrimson.com/2010/05/local-databases/ .
You can also sync it with a server once the client is online again..

Categories