1
votes

I'm trying to upload profile phoho in front end of OctoberCMS but with no luck.

Cannot catch it in the backend to save within the user.

Made everything exactly like in documentation of the CMS.

Need to make this work without any eternal plugins.

<form data-request="onCreateUser" data-request-update="user:'.res_user'" >

  <input name="file_input" type="file" >
  <button type="submit" class="subBtn">Create User</button>

</form>

In User i have:

public $attachOne = [
  'avatar' => 'System\Models\File'
];

and this code:

$file = new System\Models\File;
$file->data = Input::file('file_input');
$file->is_public = true;
$file->save();

$model->avatar()->add($file);

Record stored in DB, but its empty. filesize = 0

Can anyone please help me with this? Asked the big Bro, but found that this problem is very common, and have no solution.

Thanks

Update:

This is working, when I use this:

{{ form_open({files: true, request: 'onCreateConcert'}) }} 
 <!--File Input--> 
 <input type="file" name="file-upload"  required="required"> 
 <!--File Input--> 
 <!--Submit/Upload Button--> 
 <button type="submit">Upload</button> 
 {{ form_close() }}

but not with my form. whats i'm missing here?

I added as well token and session_key

{{ form_sessionKey() }}
    {{ form_token() }}
2
Try something like this Input::file('photo')->move($destinationPath); Input::file('photo')->move($destinationPath, $fileName); - Mittul At TechnoBrave
Also if you can help me by answering my question here stackoverflow.com/questions/40124069/… it will be great help as i am newbie in OctoberCMS. Thanks - Mittul At TechnoBrave
As so far, the problem is with octobers framework. it doesn't support XHR Need to make it or withour AJAX, or make js for this - aleXela

2 Answers

2
votes

It because you don't add enctype="multipart/form-data" to your form attribute.

When you use twig like {{ form_open({files: true, request: 'onCreateConcert'}) }}, the files: true will add attribute to your form to handle upload file. So the twig above will generate tag like below,

<form data-request="onCreateConcert" enctype="multipart/form-data">

1
votes

try this:

use System\Models\File;
use Input;

[...]

if (Input::file("file_input")) {
    $model->avatar = Input::file("file_input");
}
model->save();