I am trying to upload file. Here is my database
id
module_id
name
file
category
ext
size
Here is model:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ModuleMaterials extends Model {
public $timestamps = false;
protected $table = 'module_materials';
protected $fillable = ['module_id', 'file', 'category', 'name', 'ext', 'size'];
/*
|--------------------------------------------------------------------------
| SCOPE SECTION
|--------------------------------------------------------------------------
*/
public function scopeForModule($query, $id)
{
return $query->where('module_id', $id);
}
here is file upload:
$name = Input::get('name');
$ext = Input::get('ext');
$module_id = Input::get('module_id');
$category = Input::get('category');
$file = $name.'.'.$ext; //str_random(12);
$path = str_replace("\laravel\dev.oasis-portal.my","\dev.oasis-portal.my",base_path()).'\files\'.$module_id.'\'.$file;
$data = Request::get('file');
//if(File::makeDirectory(public_path().'\'.'TEST', 0777,true))
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
if (!is_dir(str_replace("\laravel\dev.oasis-portal.my","\dev.oasis-portal.my",base_path()).'\files\'.$module_id)) {
File::makeDirectory($path,0777,true);
}
//Write to File
$check = file_put_contents($path, $data);
$fileinformation = array( 'module_id' => $module_id, 'name' => $name, 'file' => $file, 'category' => $category,
'ext' => $ext, 'size'=> strlen($data) );
.....
Here is error:
ErrorException in LecturerController.php line 293:
Undefined offset: 1
in LecturerController.php line 293
at HandleExceptions->handleError('8', 'Undefined offset: 1', 'C:\wamp64\www\oasis_portal\laravel\dev.oasis-portal.my\app\Http\Controllers\LecturerController.php', '293', array('name' => 'taskgroup', 'ext' => 'txt', 'module_id' => '46', 'category' => 'Lectures', 'file' => 'taskgroup.txt', 'path' => 'C:\wamp64\www\oasis_portal\dev.oasis-portal.my\files\taskgroup.txt', 'data' => 'data:', 'type' => 'data:')) in LecturerController.php line 293