Hi,
I am new to this Forum. We have a new client for maintenance and while shifting their server, there are some problem in the upload functions. On the old server application works fine.
Here is the code which have been used for:
Code:
view:index.php:
$('#upload-button').click(function(e){
e.preventDefault();
var name = $(".fileinput-filename1").html();
$('#multiple_upload_form').ajaxForm({
beforeSubmit:function(e){
$('.uploading').show();
},
success:function(e){
$('.uploading').hide();
$('.fileinput .close').click();
$('#upload-alert').show();
$('#upload-alert').removeClass('alert-error').addClass('alert-success');
$('#upload-alert p').html('<strong>Success!</strong> File has been succesfully upload.');
dataTable.draw();
},
error:function(e){
$('#upload-alert').show();
$('#upload-alert').removeClass('alert-success').addClass('alert-error');
$('#upload-alert p').html('<strong>Error!</strong> Something Wrong.');
alert(e);
}
}).submit();
});
Assets.php (controller):
<?php namespace App\Controllers\Admin;
use CodeIgniter\Controller;
use App\Models\Admin\AssetModel;
use App\Models\Admin\AssetCategoryModel;
class Asset extends Controller
{
public function index()
{
isProtected();
if(isPostBack()){
$model = new AssetModel();
$filters['name'] = $this->request->getPost('name');
$filters['category'] = $this->request->getPost('category');
$order = $this->request->getPost('order');
$start = $this->request->getPost('start');
$length = $this->request->getPost('length');
$list = $model->getList($filters,$order,$start, $length);
$totalResults = $model->getTotalResults($filters);
$requestData= $_REQUEST;
$json_data = array(
"draw" => intval($requestData['draw']),
"recordsFiltered" => $totalResults,
"recordsTotal" => $totalResults,
"data" => $list
);
echo json_encode($json_data);exit();
}
else
{
$model = new AssetCategoryModel();
$data['categories'] = $model->getList();
return admin_render("asset/index",$data);
}
}
public function popup($fieldName='asset_upload')
{
isProtected();
if(isPostBack()){
$model = new AssetModel();
$filters['name'] = $this->request->getPost('name');
$filters['category'] = $this->request->getPost('category');
$order = $this->request->getPost('order');
$start = $this->request->getPost('start');
$length = $this->request->getPost('length');
$list = $model->getList($filters,$order,$start, $length);
$totalResults = $model->getTotalResults($filters);
$requestData= $_REQUEST;
$json_data = array(
"draw" => intval($requestData['draw']),
"recordsFiltered" => $totalResults,
"recordsTotal" => $totalResults,
"data" => $list
);
echo json_encode($json_data);exit();
}
else
{
$model = new AssetCategoryModel();
$data['categories'] = $model->getList();
$data['fieldName'] = $fieldName;
return view("backend/asset/popup",$data);
}
}
public function uploadImage()
{
isProtected();
if(isPostBack()){
$model = new AssetModel();
$files = $this->request->getFiles();
$category = $this->request->getPost('category');
$model->fileUpload($category,$files->all()['images']);
}
}
public function edit($id)
{
isProtected();
$model = new AssetCategoryModel();
$data['categories'] = $model->getList();
$model = new AssetModel();
$data['asset'] = $model->find($id);
//print_array($data['categories']);exit();
$rules = [
'name' => 'required|min_length[3]',
];
if(isPostBack()){
$data["name"] = $this->request->getPost('name');
$data["asset_category_id"] = $this->request->getPost('category');
$data["updated_at"] = current_date();
if($this->validate($rules))
{
if($model->update($id,$data)){
$data['asset']['asset_category_id'] = $data["asset_category_id"];
set_flashdata("success","Asset Category has been succesfully saved!");
//redirect(site_url("admin/asset/categories"));
}
else
set_flashdata("error","Something Wrong!");
}
}
$data["flashdata"] = get_flashdata();
$data['validation'] = $validation = \Config\Services::validation();
$data['errors'] = $validation->getErrors();
return admin_render("asset/edit",$data);
}
public function delete($id)
{
isProtected();
if(isPostBack()){
$model = new AssetModel();
$data = $model->find($id);
if($data)
{
if(file_exists(upload_path($data['image'])))
unlink(upload_path($data['image']));
$model->delete($id);
return $this->response->setStatusCode(200, 'OK');
}
}
return $this->response->setStatusCode(404, 'Nope. Not here.');
}
public function categories()
{
isProtected();
if(isPostBack()){
$model = new AssetCategoryModel();
$filters['name'] = $this->request->getPost('name');
$start = $this->request->getPost('start');
$length = $this->request->getPost('length');
$list = $model->getList($filters,NULL,$start, $length);
$totalResults = $model->getTotalResults($filters);
$requestData= $_REQUEST;
$json_data = array(
"draw" => intval($requestData['draw']),
"recordsFiltered" => $totalResults,
"recordsTotal" => $totalResults,
"data" => $list
);
echo json_encode($json_data);exit();
}
else
{
return admin_render("asset/cat-index");
}
}
public function catAdd()
{
isProtected();
$rules = [
'name' => 'required|min_length[3]',
];
if(isPostBack()){
$data["name"] = $this->request->getPost('name');
$data["description"] = $this->request->getPost('description');
$data["created_at"] = current_date();
if($this->validate($rules))
{
$model = new AssetCategoryModel();
$model->save($data);
set_flashdata("success","Asset Category has been succesfully created!");
redirect(site_url("admin/asset/categories"));
}
}
$data["flashdata"] = get_flashdata();
$data['validation'] = $validation = \Config\Services::validation();
$data['errors'] = $validation->getErrors();
return admin_render("asset/cat-add",$data);
}
public function catEdit($id)
{
isProtected();
$model = new AssetCategoryModel();
$data['cat'] = $model->find($id);
//print_array($data['cat']);exit();
$rules = [
'name' => 'required|min_length[3]',
];
if(isPostBack()){
$data["name"] = $this->request->getPost('name');
$data["description"] = $this->request->getPost('description');
$data["updated_at"] = current_date();
if($this->validate($rules))
{
if($model->update($id,$data)){
set_flashdata("success","Asset Category has been succesfully saved!");
//redirect(site_url("admin/asset/categories"));
}
else
set_flashdata("error","Something Wrong!");
}
}
$data["flashdata"] = get_flashdata();
$data['validation'] = $validation = \Config\Services::validation();
$data['errors'] = $validation->getErrors();
return admin_render("asset/cat-edit",$data);
}
public function catDelete($id)
{
isProtected();
if(isPostBack()){
$model = new AssetCategoryModel();
$data = $model->find($id);
if($data)
{
$model->delete($id);
return $this->response->setStatusCode(200, 'OK');
}
}
return $this->response->setStatusCode(404, 'Nope. Not here.');
}
}
Could somebody please help me to resolve the issue. No error code shown, only uploading error message shown on the page. I have checked php version, server configuration as well. everything is fine. I have attached screenshot of the error.
Thanks in advance.
Attached Files
Thumbnail(s)