I need upload file from frontend and add this file to email address with attach, but have always error...
PHP Warning: file_get_contents(/tmp/php3ItUlo): failed to open stream: No such file or directory
Action where form is created:
FileForm.php -> extends Page
function fileSendForm() {
$upload = new FileField('picture', 'Add your file *');
$fields = new FieldList(array($upload));
$actions = new FieldList( new FormAction('SendFileForm', 'Send'));
$form = new Form($this, 'SendFileForm', $fields, $actions);
return $form;
}
Form Post to that function:
FileForm_Controller.php -> extends Page_Controller
function SendFileForm($data) {
$email = new Email(ltrim($from), ltrim($to), ltrim($assunto_field), $body);
if ( !$_FILES["picture"]["error"] > 0 ) {
error_log( "Name: " . $_FILES["picture"]["name"]);
error_log( "Type: " . $_FILES["picture"]["type"]);
error_log( "Size: " . ($_FILES["picture"]["size"] / 1024) . " kB");
error_log( "Save in: " . $_FILES["picture"]["tmp_name"]);
move_uploaded_file($_FILES["picture"]["tmp_name"], $_FILES["picture"]["name"]);
}
$imagedata = file_get_contents($_FILES["picture"]["tmp_name"]);
if (is_uploaded_file($_FILES["picture"]["tmp_name"])) {
$email->attachFile($_FILES["picture"]["tmp_name"], $_FILES["picture"]["name"]);
}
$email->send();
}
The error_log when submit the file 013.jpg have this
Nome: 013.jpg
Type: image/jpeg
Size: 91.654296875 kB
Save in: /tmp/php3ItUlo
PHP Warning: file_get_contents(/tmp/php3ItUlo): failed to open stream: No such file or directory
Email was sent but without have attach file
What do wrong?