0

*I want to upload a file from a form, and in the CMS system it impresses me that the file is 0 bytes - I need help viewing the file *

html file:

{{ form_ajax('contactfrom::onSend', { files: 'true',  flash: 'true', 'data-request-files':true, 'data-request-validate': true }) }}
<form action="ContactForm.php" method="post" data-request="contactfrom::onSend" enctype="multipart/form-data" data-request-validate data-request-files>
    <div class="form-group">
        <label>Your name</label>
        <input type="name" name="name" id="yourName" class="form-control" placeholder="Full Name" required />
    </div>

    <div class="form-group">
        <label>file input</label>
        <input type="file" name="file" id="file" class="form-control-file" accept=".jpg, .jpeg, .png" multiple="multiple" />
    </div>

    <button align="right" type="sumbit" name="post" class="btn btn-success" value="Post" style="float: right;" ;>
        Create
    </button>
</form>
{{ form_close() }}

php file:

public function onSend() {
    
    $vars = [ 
      'name' => Input::get('name'),
      'file' =>Input::file('file'),
      'content'=> Input::get('content')
    ];

    $infri = new Infringement();
    $infri->name    = Input::get('name');
    $infri->file    = Input::file('file');
    $infri->save();    
}

and I put:

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

and i see in my octoberCMS - file - 0 byte. and if i try check the file :

if(Input::has("file")) {
    echo ", #>file";
} else {
    echo ", no file";
}

is return "#>file" . please help.

Hardik Satasiya
  • 9,547
  • 3
  • 22
  • 40
  • I guess issue is, you added `form` tag twice `( form_ajax as well
    )`. just remove inner form tag `
    – Hardik Satasiya Sep 21 '20 at 13:18
  • i try , but still not working – almog19943 Sep 21 '20 at 13:41
  • can you share dumping output `dd($vars)` inside your `onSend` and inspect using dev tools and share us request output – Hardik Satasiya Sep 21 '20 at 14:41
  • [ 'name' => Input::get('name'),'email' => Input::get('email'), 'country' =>Input::get('country'),'url' =>Input::get('url'), 'message' =>Input::get('message'),'file' =>Input::file('file'), 'content'=> Input::get('content')]; – almog19943 Sep 22 '20 at 09:34
  • i am not sure but its not dump of $var i think you are missing some thing it should be like ['name' => 'name you input in textbox ' .... and so on` ']. like that – Hardik Satasiya Sep 22 '20 at 09:45
  • $infri = new Infringement(); $infri->avatar = Input::file('file'); but $var is just for the email.. i put that and i see 0 byte in CMS october – almog19943 Sep 22 '20 at 09:57
  • hmm are you sure you know how to use dump using `dd -> dump and die` Laravel api, as given out-puts are not expected dumps – Hardik Satasiya Sep 22 '20 at 10:39
  • but in October writhing with this Label : $infri->avatar = Input::file('file'); from the form validate – almog19943 Sep 22 '20 at 10:51
  • I’m voting to close this question because it seems author do not have knowledge of php or Laravel, so its pointless to start jumping in to CMS i guess – Hardik Satasiya Sep 22 '20 at 12:41

0 Answers0