Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[SS3] - upload file from frontend


Go to End


2 Posts   3320 Views

Avatar
pouic

Community Member, 19 Posts

2 August 2013 at 2:16am

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?

Avatar
anselmdk

Community Member, 18 Posts

25 February 2014 at 11:30am

It looks like SilverStripe is trying to store the uploaded image in your server's temp directory and for some reason isn't allowed to. Have you tried to create a "silverstripe-cache" directory in your web root?