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!
Related
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.
I'm trying to set up a file upload for my website but I'm not sure what I'd need to get this to work overall. I'm trying to use Jquery File Upload but I can't seem to get the files to upload to my server. It looks like I might need something else to get it to run but I'm not sure what. Any suggestions?
There are three "sides" to a file upload.
First is client-side: You need to have a form that can upload files (so you need to set the enctype attribute of your form element, and set your action to post).
Second is server-side: You need something that can handle the file upload. Assuming you're using a server with PHP, you can access the file via $_FILES['filename']. Google has a vast array of example for handling file uploads.
Third is server-side (again) - your server must allow file uploads. Not only must it allow file uploads, but it restricts the size of the file that can be uploaded (php config).
However, it looks like jquery file upload has a PHP file handler.
I will sugest you use dreamweaver its easy to use expecially to upload files to the web n you can also see the steps needed in its help content. or you may download an ftp uploader
How could I extract the METADATA / METAINFO / everything that would describe the REMOTE FILE without downloading it in the first place?
do you have some snippets in PHP?
how about in cURL?
or any language?
thanks
You can't get all the metadata from a file without downloading the entire file, as you have no way of knowing how much of the file you need before you've captured its metadata block, some file formats store metadata at the end of the file (meaning you'll need the entire file anyway), some files don't have any metadata embedded in them at all, and so on.
If you do a HEAD request, you will usually be able to get some basic metadata on the file in question in the form of the content-type and content-length headers returned by the server, but this is typically limited to the MIME type and the file size (and if you're dealing with a script that serves the file and that script doesn't set the necessary headers, you might not even get that).
I want to upload a file to my server from some application. How can I code a PHP page to accept this file?
The application should just include the file in an HTTP POST request as would an HTML form with an input of type file. In the PHP code, the posted file contents would be available in the $_FILES array.
Lots more information here.
Keep in mind that the concept of a "file" doesn't mean the same thing over HTTP that it does on a local computer or on the target server. In HTTP, the "file" is just a stream of data wrapped in an HTTP request or response with a given content type and various other headers, no different from a web page or an image or any other request/response.
I would suggest reading the PHP manual chapter on handling file uploads
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.