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?
Related
Hi I am wondering if the input field with type "file" is automatically uploading files to the server when there is a file selected by the user.
The thing I want is that a user can select files to submit it and that a PHP FTP connection is established to upload the files.
I am not sure if the browser pre-uploads the files to a temp directory on the server or does it do that only when you hit the submit button?
Because if the file is already uploaded to the server it would be unnecessary to use FTP to upload the file again only to a different location on the server.
Basically what I want to accomplish is something similar to what we transfer does. I believe they are not uploading before the user hits the button.
Can anybody point me in the right direction and provide me with some extra info about this matter. Haven't found the desired information yet.
Thanks in advance.
The file is uploaded only once the form is submitted (in the same HTTP POST request as all other form fields). Why don't you try it, to see yourself?
And you cannot use PHP to upload a file via FTP from a client to a server. That's not possible. PHP runs on the server, it cannot access files on a client's machine. See also:
Upload a local file from application via web server with PHP code to FTP server
PHP uploading file from browser to FTP.
Is it possible to send file from a local URL?
I need to upload files in php from your local url, eg I open the web page with:
www ... upload.php?url=c://...file.jpg,
from the url GET,I would get the file on the pc and would upload, without using html or anything else that I have to choose, just with the file url.
Important, it can only be this way, it will not be possible to choose the file during the upload, it will only be a POST or GET with the local url.
I researched and found nothing related, if anyone can help
I think it is impossible for server to get a client file by using the file path.
But maybe you can use JS and FileSystemobject to prepare the file, make it to streaming and post to the server.
And you must know FSO need a high security permission and may be disabled on users' browser.
I'm developing a REST API with Laravel as the backend of my app. The frontend is made with React/Redux. The server is a Windows IIS machine.
I'm having a problem submiting a list of attachments to a model. The upload process from the frontend is the following one:
User fills a form with a dynamic list of custom file fields.
Every time file is chosen, it uploads the file to a temporary folder using the API, and returns an url of the file.
When the user feels like uploading them all, it loops through all attachment fields and calls the API to create the attachment for the model. The controller receives the temporary URL, fetches the file using file_get_contents, and stores it somewhere else.
So in the end, we can have multiple concurrent requests, each calling file_get_contents to an url located in the same server, which shouldn't be a problem.
Problem is it crashes when I upload more then 1 file, but it's random. So the more files I upload, more probability of crashing. It crashes 100% of the times with more than 3 files. All requests are seen as pending on Chrome dev tools, and after some minutes they return "Error 500 failed to open stream: HTTP request failed!".
Things I've tried:
Use cURL. Same result.
allow_fopen_url PHP option is On
Firewall is disabled
Tried multiple machines
Requests don't fail if the URL is external to the server, meaning file_get_contents fetches a URL located in another machine.
Looks like a race condition to the filesystem. But I don't understand why, all files that need to be read are different.
Don't know what else to do. Can somebody help?
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.
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.