Jump to:

1971 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » [SS3] - upload file from frontend

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

Page: 1
Go to End
Author Topic: 544 Views
  • pouic
    Avatar
    Community Member
    16 Posts

    [SS3] - upload file from frontend Link to this post

    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?

  • anselm.dk
    Avatar
    Community Member
    18 Posts

    Re: [SS3] - upload file from frontend Link to this post

    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?

    544 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.