conxeptbox Newbie
Posts: 4
Threads: 1
Joined: May 2018
Reputation:
0
05-17-2018, 05:18 AM
(This post was last modified: 05-21-2018, 12:21 AM by conxeptbox .)
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)
conxeptbox Newbie
Posts: 4
Threads: 1
Joined: May 2018
Reputation:
0
(05-17-2018, 10:55 AM) php_rocs Wrote: @conxeptbox ,
Did you check to make sure that the directory where the upload is going has the correct permissions (on the new server)?
Thank you for your quick response. I checked all permissions are fine. All directories and sub-directories have write permission. Is there any issue possible with the server?
Thanks again for quick help!
InsiteFX Super Moderator
Posts: 6,744
Threads: 346
Joined: Oct 2014
Reputation:
247
Also check your php.ini file.
memory_limit = 32M
these two below should always be the same size.
upload_max_filesize = 32M
post_max_size = 32M
These setting's can effect any file upload type's.
What did you Try? What did you Get? W hat did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
conxeptbox Newbie
Posts: 4
Threads: 1
Joined: May 2018
Reputation:
0
(05-18-2018, 03:27 AM) InsiteFX Wrote: Also check your php.ini file.
memory_limit = 32M
these two below should always be the same size.
upload_max_filesize = 32M
post_max_size = 32M
These setting's can effect any file upload type's.
Hi InsiteFX,
Thanks for your response. This was not set as you defined, but after changing the values, we still facing the same issue. Is there any other possible issue which help uploading the assets files to the server.
We have checked each and every bit of code, nothing suspicious. Maybe we missed something.
Thanks again for quick help.
Conxeptbox
scalla Member
Posts: 71
Threads: 16
Joined: Jul 2017
Reputation:
0
(05-19-2018, 03:57 AM) It might be better to do a var_dump to check the return response ,that would help to figure out what\s wrong conxeptbox Wrote: (05-18-2018, 03:27 AM) InsiteFX Wrote: Also check your php.ini file.
memory_limit = 32M
these two below should always be the same size.
upload_max_filesize = 32M
post_max_size = 32M
These setting's can effect any file upload type's.
Hi InsiteFX,
Thanks for your response. This was not set as you defined, but after changing the values, we still facing the same issue. Is there any other possible issue which help uploading the assets files to the server.
We have checked each and every bit of code, nothing suspicious. Maybe we missed something.
Thanks again for quick help.
Conxeptbox
rajeshgoyalg Newbie
Posts: 1
Threads: 0
Joined: May 2018
Reputation:
0
Check mime-type of the uploaded file on the server and set that mime-type in config -> mimes.php.
InsiteFX Super Moderator
Posts: 6,744
Threads: 346
Joined: Oct 2014
Reputation:
247
You would need to change,
upload_max_filesize = 32M
post_max_size = 32M
To the largest size of the files you are uploading.
See what the file sizes are then set them up.
What did you Try? What did you Get? W hat did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
conxeptbox Newbie
Posts: 4
Threads: 1
Joined: May 2018
Reputation:
0
(05-19-2018, 05:02 AM) scalla Wrote: (05-19-2018, 03:57 AM) It might be better to do a var_dump to check the return response ,that would help to figure out what\s wrong conxeptbox Wrote: (05-18-2018, 03:27 AM) InsiteFX Wrote: Also check your php.ini file.
memory_limit = 32M
these two below should always be the same size.
upload_max_filesize = 32M
post_max_size = 32M
These setting's can effect any file upload type's.
Hi InsiteFX,
Thanks for your response. This was not set as you defined, but after changing the values, we still facing the same issue. Is there any other possible issue which help uploading the assets files to the server.
We have checked each and every bit of code, nothing suspicious. Maybe we missed something.
Thanks again for quick help.
Conxeptbox
Thanks again for your response. I am getting the error in javascript written in view file, so i put 'console.log(e);' instead of var_dump(); Here is the output of console.log(e); :-
{readyState : 4 , getResponseHeader : ƒ, getAllResponseHeaders : ƒ, setRequestHeader : ƒ, overrideMimeType : ƒ, …}
abort :ƒ (a)
arguments :null
caller :null
length :1
name :" abort"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:4
[[Scopes]] :Scopes[3]
always :ƒ ()
arguments :null
caller :null
length :0
name :" always"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
complete :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
done :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
error :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :
constructor :ƒ ()
__proto__ :Object
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
fail :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :
constructor :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
__proto__ :Object
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
getAllResponseHeaders :ƒ ()
arguments :null
caller :null
length :0
name :" getAllResponseHeaders"
prototype :
constructor :ƒ ()
__proto__ :Object
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:4
[[Scopes]] :Scopes[3]
getResponseHeader :ƒ (a)
arguments :null
caller :null
length :1
name :" getResponseHeader"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:4
[[Scopes]] :Scopes[3]
overrideMimeType :ƒ (a)
arguments :null
caller :null
length :1
name :" overrideMimeType"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:4
[[Scopes]] :Scopes[3]
pipe :ƒ ()
arguments :null
caller :null
length :0
name :" then"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
progress :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
promise :ƒ (a)
arguments :null
caller :null
length :1
name :" promise"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
readyState :4
responseText :" <!doctype html>↵<html>↵<head>↵ <meta charset="UTF-8">↵ <meta name="robots" content="noindex">↵↵ <title>Whoops!</title>↵↵ <style type="text/css">↵ body { height: 100%; background: #fafafa; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: #777; font-weight: 300; margin: 0; padding: 0; } h1 { font-weight: lighter; letter-spacing: 0.8; font-size: 3rem; color: #222; margin: 0; } h1.headline { margin-top: 20%; font-size: 5rem; } .text-center { text-align: center; } p.lead { font-size: 1.6rem; } .container { max-width: 75rem; margin: 0 auto; padding: 1rem; } .header { background: #85271f; color: #fff; } .header h1 { color: #fff; } .header p { font-size: 1.2rem; margin: 0; line-height: 2.5; } .header a { color: rgba(255,255,255,0.5); margin-left: 2rem; display: none; text-decoration: none; } .header:hover a { display: inline; } .footer .container { border-top: 1px solid #e7e7e7; margin-top: 1rem; text-align: center; } .source { background: #333; color: #c7c7c7; padding: 0.5em 1em; border-radius: 5px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; margin: 0; } .source span.line { line-height: 1.4; } .source span.line .number { color: #666; } .source .line .highlight { display: block; background: #555; color: #fff; } .source span.highlight .number { color: #fff; } .tabs { list-style: none; list-style-position: inside; margin: 0; padding: 0; margin-bottom: -1px; } .tabs li { display: inline; } .tabs a:link, .tabs a:visited { padding: 0rem 1rem; line-height: 2.7; text-decoration: none; color: #a7a7a7; background: #f1f1f1; border: 1px solid #e7e7e7; border-bottom: 0; border-top-left-radius: 5px; border-top-right-radius: 5px; display: inline-block; } .tabs a:hover { background: #e7e7e7; border-color: #e1e1e1; } .tabs a.active { background: #fff; } .tab-content { background: #fff; border: 1px solid #efefef; } .content { padding: 1rem; } .hide { display: none; } .alert { margin-top: 2rem; display: block; text-align: center; line-height: 3.0; background: #d9edf7; border: 1px solid #bcdff1; border-radius: 5px; color: #31708f; } ul, ol { line-height: 1.8; } table { width: 100%; overflow: hidden; } th { text-align: left; border-bottom: 1px solid #e7e7e7; padding-bottom: 0.5rem; } td { padding: 0.2rem 0.5rem 0.2rem 0; } tr:hover td { background: #f1f1f1; } td pre { white-space: pre-wrap; } .trace a { color: inherit; } .trace table { width: auto; } .trace tr td:first-child { min-width: 5em; font-weight: bold; } .trace td { background: #e7e7e7; padding: 0 1rem; } .trace td pre { margin: 0; } .args { display: none; } </style>↵</head>↵<body>↵↵ <div class="container text-center">↵↵ <h1 class="headline">Whoops!</h1>↵↵ <p class="lead">We seem to have hit a snag. Please try again later...</p>↵↵ </div>↵↵</body>↵↵</html>↵"
setRequestHeader :ƒ (a,b)
arguments :null
caller :null
length :2
name :" setRequestHeader"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:4
[[Scopes]] :Scopes[3]
state :ƒ ()
arguments :null
caller :null
length :0
name :" state"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
status :500
statusCode :ƒ (a)
arguments :null
caller :null
length :1
name :" statusCode"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:4
[[Scopes]] :Scopes[3]
statusText :" Internal Server Error"
success :ƒ ()
arguments :null
caller :null
length :0
name :" add"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
then :ƒ ()
arguments :null
caller :null
length :0
name :" then"
prototype :{constructor : ƒ }
__proto__ :ƒ ()
[[FunctionLocation]] :jquery.min.js:2
[[Scopes]] :Scopes[3]
__proto__ :
constructor :ƒ Object()
hasOwnProperty :ƒ hasOwnProperty()
isPrototypeOf :ƒ isPrototypeOf()
propertyIsEnumerable :ƒ propertyIsEnumerable()
toLocaleString :ƒ toLocaleString()
toString :ƒ toString()
valueOf :ƒ valueOf()
__defineGetter__ :ƒ __defineGetter__()
__defineSetter__ :ƒ __defineSetter__()
__lookupGetter__ :ƒ __lookupGetter__()
__lookupSetter__ :ƒ __lookupSetter__()
get __proto__ :ƒ __proto__()
set __proto__ :ƒ __proto__()
conxeptbox.