I'm making a website and my page is in PHP and posts a form to another website which returns a zip file which the browser downloads directly. But the problem is that one file needs to be added to the zip. So how can I save the zip to my website to modify it before it's getting downloaded?
If the action of the form is pointing to another site, then there is no way for you to manipulate the response.
You need to change your form to post to your own site, then have your server make the HTTP request to the other site, parse the response, edit the zip file and then return it to the client.
Related
I have a custom system running on a server which expects a certain file type.
when uploading a file via posts, the $_FILES variable in PHP contains information such as [type] = image/png. Where does this information come from?
When i manually try to curl to my website via SSH, and i add -F "file=#/a/b/c/d.pqx" the type is set to "application/octet-stream".
Is the curl command translating the uploaded file and suppling this information or is the server/php parsing the file and providing this information?
Is it possible to make a POST request to my website and have the filetype show up as "application/pqx" (pqx is a custom file extension) ? I am more interested in a way to make the right POST request rather than changing the PHP code. Can i customize the curl request to the website and supply the filetype myself?
thanks for all your help!
I have a wordpress site where I want users to be able to upload files to the api url of a separate server called Server2.
I have been able to get this to work in two separate ways, but each has it's drawbacks.
Option 1)
Redirecting back to the page itself on the action of the form allows me to submit via curl on the post and upload the file to Server2, but first it uploads the files to the temp location on the webserver. The webserver is limited in the size of files it can transfer and it also involves sending the file twice.
Option 2) Set the action of the form to the receiving url on Server2. Works well with the file upload and we don't run into the size limitation, but on the completion of the upload, the page goes to the url of Server2 and displays the result message from the upload. I don't have access to Server2 to redirect back.
I would like to be able to post the file to Server2 without actually going to the page as we do with curl, without having to upload the file to the webserver first. Is this possible?
I have a WordPress site, in which type1 users can upload *.doc files and type2 users should be able to open them by clicking on a link which represents a file.
The file then should be opened in a new window of the browser.
I got the first part easily - there are many guides on uploading a file.
But I couldn't find one that goes through all the steps of getting and opening a file which resides on a server directory.
I assume clicking the link should cause an ajax request which will send the file key to the server.
The server can then get from the MySQL DB the file name and location.
But what do I do then?
How do I get the file from the server directory, send it back to the client and open it for reading in the browser?
Edit:
I want the files to be confidential and not let just anyone read them so giving the users the link for the file on the server isn't the right way.
I still think I need to send the file from the server directory to the client.
How can this be done?
You can add links to uploaded media in WordPress easily. Just remember to link to the actual file:
I want the files to be confidential and not let just anyone read them so giving the users the link for the file on the server isn't the right way.
Yes it is. You can't let people read the document without giving them the document.
If you want to keep it confidential, then require the users to agree not to share the link with anyone else. Or go further and add a layer of authentication + authorisation and also require that users not hand over their credentials.
Simply, redirect the browser to the location of the file. It's depend on user's browser settings that file opens on the browser directly, or user sees open/save dialog.
But, if you want to open the file inside the browser without letting user download it, you should redirect her/him to a custom page. e.g. a page that loads a doc editor.
There's no way to show a Microsoft Word file inside the browser unless they install proper software. e.g. an Applet or ActiveX or something that be able to open MSWord files.
Consider using WP Client File Share plugin.
I have a link to a download to a file that calls a php script before it starts downloading the file. Is it possible to somehow get the location of the file that is to be downloaded directly (maybe through some browser plugin)?
I need this because I want to use wget on another system to download the file directly. A problem might be authentication because I need to provide a username and password, but getting the file location URL is the first step I think.
Thanks,
Ivan
If the PHP script directly reads the file, no, you will never get the real location of that file.
If it redirects to it, yes, it's possible using the Firebug "net" tab or Live HTTP headers extension.
For image upload we use FILE html controller.
How this html controller able to browse in the local system?
After selecting a file , it will be copied and moved to server location.
If the php is ale to copy the local file and move to server , will it be able to do any other manipulations of that file ? like delete!
What is happening actually on file upload?
The HTML control is provided by the browser. The browser is a local application and has access to the user's file system. The file's contents are sent to the receiving script by the browser using standard methods.
PHP has no access to the user's file system at any point, just the copy provided by the browser. Deleting or even reading files on the user's file system is not possible.
Actually php is not accessing local system. After you choose a file and click upload at upload form. The whole file(not location) is sent via POST request. And php just recieves that POST request with the whole file, and stores at server.