sorry if this might be a cheesy question, but unfortunately I cannot change the project setup. I have a form on a php page, which is supposed to post some text fields and a file input to a MVC Controller Action. The posting part works, and I successfully receive the text data in my ViewModel. However, I have no idea how tto receive the file (image, will be either jpg or png). The ID and NAME of the input type file is "UserIcon".
In the ActionResult I tried it with HttpPostedFileBase like this:
public virtual ActionResult RegisterJson(RegistrationModels model, HttpPostedFileBase UserIcon)
But UserIcon is always NULL. Instead, if I have the file as part of the RegistrationModels
Model:
[DisplayName("Ihr Foto")]
public string UserIcon { get; set; }
I receive the curl path: @C:\\Windows\\Temp\\phpA03D.tmp;filename=Penguins.jpg;
as string.
But from here I have absolutely no clue as to what I have to do next to save the file. I tried to add to the curl header the $header = array("Content-type: multipart/form-data");
but then all the posted form fields are NULL.
I'd be so grateful if anyone could point me in the right direction! I think I'm having a main blackout here and doing something completely wrong :-S
This is the curl code which posts to the MVC Action:
$postargs = array();
foreach ($_FILES as $param => $file) {
$postargs[$param] = '@' . $file['tmp_name'] . ';filename=' . $file['name'] . ';';
}
$fields_string = "";
//url-ify the data for the POST
foreach($_POST as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
$fields_string .= http_build_query($postargs);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($_POST));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
Thanks alot!!
Cheers, Caroline