<?php namespace Pratik\Controllers;

use CodeIgniter\Controller;
use Pratik\Models\Pratik_Model;

class FileUpload extends Controller
{
	public $model;
	public $ajaxresult;

    function __construct()
	{

        $this->model = new Pratik_Model();
        $this->session = \Config\Services::session();
		$this->request = \Config\Services::request();
		$this->ajaxresult = array('refresh'=>0,
								   'redirect'=>0,
								   'id'=>'',
								   'state'=>'1',
								   'data'=>'',
								   'message'=>'Geçersiz İşlem',
								   'html'=>'',
								  );
		if(!isset($_POST['formtoken']) || $this->session->get('formtoken')!=$this->request->getGetPost('formtoken'))
		{
			//echo json_encode($this->ajaxresult,true);
			//die();		
		}

    }
	public function index()
	{
		print_r($files);
	}	
	
	public function uploadfile()
	{
		$files = $this->request->getFiles();
		if($files)
		{
			foreach($files as $file)
			{

				$newName = $file->getRandomName();
				$file->move(WRITEPATH.'uploads/images', $newName);		
				$this->ajaxresult['data']= 	WRITEURL.'uploads/images/'.$newName;
				$this->ajaxresult['id']= 	$newName;
			}
		} else {
			
		}
		echo json_encode($this->ajaxresult,true);
		die();			

	}
}