Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 414 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OctoberCMS frontend image upload

#1
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() }}
Reply

#2
try this:

use System\Models\File;
use Input;

[...]

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

#3
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">
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through