For my RESTFUL API server I'm trying to use the "PUT" method for uploading a file.
Actions started as reading php://input.
So, how can pass file name or some other parameters to action and display them?
You can use post method therefore, you can collect data from form-data using $_POST the super global variable because, there is no super global like $_PUT for put method.
Related
I have a menu that is in an iframe. The user selects an option from the menu to log in and after the credentials are verified (using mySQL) (via a call to href='login.php') - I need to access several variables (such as the object handle to the mySQL connection ($dbconnection), user id ($userid) value. I have declared these variables as globals and they appear= to be inaccessible from the launch of href="other.php" menu option. I have tried to put these as $GLOBALS and the same results - they are inaccessible from the launch of href="other.php" menu option.
Passing these variables in the href call via the use of ? and & is not a good solution (and besides you cannot pass an object such as a Data Base handle. I need these variables in other files I open from the menu via the href.
What is the best way to have this functionality?
Jack
I found a solution to the problem. In order to pass variables to called PHP files via the HREF I had to put these variables in the SESSION global. I then did a $enc=session_encode() which encodes into a string all the user defined session variables and then I passed the string value to the called file via the use of the ? after the file being called. In the file that I called, I pulled the passed encoded SESSION string via a $GET and then used the value from the $GET to call session_decode (). That seemed to work. I am also thinking of hashing and salting this encoded string so that it is not easy to hijack it.
The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms.
Is there a way in code igniter to access GET and POST both data through one predefined variable or function
You can use
$this->input->post_get('some_data', TRUE);
This will work like $_REQUEST.More function are there like cookie,server.
For more information check here
I have a REST service where I want to update a file over PUT.
When I use POST I used the following to get the uploaded file:
/**
* #var Request $request
*/
$request->files->get('file');
How to get an uploaded file send as PUT in Symfony Framework?
When you receive a POST request, you get a form submitted with one or more fields, and these fields include any files (possibly more than one file). The Content-Type is multipart/form-data.
When you PUT a file, the file's data is the request body. It's like the opposite of downloading a file with GET, where the file's content is the response body. In this case, if you receive a JPG file via a PUT request, the Content-Type will be image/jpeg. Of course this means you can only submit one file with each PUT request.
You should therefore use $request->getContent() to receive the data. If the content has other information in addition to the submitted file, then technically speaking it is a malformed PUT request, and should probably be sent as a POST instead.
Although you can't send any other fields with a PUT request, you can still use the query string to provide some additional short fields where appropriate. For example you might upload a file via a PUT request to /api/record/123/attachment?filename=example.pdf. This would allow you to receive both an uploaded file, another data field (the filename) and the ID (123) of the record to attach the upload to.
The easiest way where you don't need to change your api you submit the file and data you want to change as method POST and add query parameter ?_method=PUT to the url. In your front controller app.php/index.php you need to enable this feature with:
Request::enableHttpMethodParameterOverride();
I use RESTFullYii v1.15 from here . RESTFullYii does not get data for PUT request
I faced the problem that making PUT method the data I submit are not inside the doRestUpdate($id, $data) function.
In the link above it is defined as public function doRestUpdate($id, $data).
So it is supposed that data are submit are in $data variable.
Vars $_GET, $_POST, $_REQUEST don't have these data too.
I watch headers of request using firebug and see that data are sent in PUT request, but they are not in doRestUpdate function.
If there is way to fix it?
I call my php file in the browser with "...test.php?text=Hello" but the $_POST variable stays empty (also print_r($_POST) returns array() ).
Why? Do I need to activate the post variable or something?
Thanks.
Variables passed in through the URL end up inside $_GET, not $_POST.
$_POST contains variables parsed by reading the HTTP request body when the method is POST. In this case the method is not POST and there is also no request body.
If you pass the variable through the URL you use $_GET.
Also, you will access the variable with:
$_GET['text']
This is a array that is sent through and you need to specify what item in the array you want to use.
...test.php?text=hello passes data via the GET method (accessible via $_GET in the processing script).
$_POST gets populated by forms or cURL access (when the transfer method is defined as "post")