If you want to be able to access the file's contents using $app->request->post('content');
, your curl request must use a <
instead of an @
for the content
field,
curl -i http://localhost/test/index.php -X POST -F "name=file.png" \
-F "content=</var/www/html/test/file.png"
From curl's manpage:
To force the
'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload,
while the < makes a text field and just get the contents for that text field from a file.
By using @
, you marked the field as a file. Technically, this adds a Content-Disposition
header to the field (RFC 2388, if you're interested). PHP detects that and automatically stores the field inside $_FILES
instead of $_POST
, as Raphaël Malié remarked in a comment, which is why you can't access the contents using $app->request->post
.
You should consider to switch to using $_FILES
in your backend, though, if you want to support uploading using browsers' <input type=file>
elements and forms. Those always set a Content-Disposition
header.