Laravel saving image in storage - ajax

my code was working fine but now it is not, as image is not saving in folder, i am trying to save image in storage folder, with id as image name.
Controller:
if($request->hasFile('profile_pic')){
if (Input::file('profile_pic')->isValid()) {
$file = Input::file('profile_pic');
$destination = 'storage/app/teachers'.'/';
$ext= $file->getClientOriginalExtension();
$mainFilename = $teacher->id.request()->$ext;
$file->move($destination, $mainFilename.".".'jpg');
echo "uploaded successfully";
}
View: where 0000 is default image.
<div class="row">
<a href="#"> <img id="imgFileUpload" name="profile_pic" src={{asset('storage/app/teachers/'.'0000'.'.jpg')}} value="{{#$teacher->id}}"
onerror="this.src='storage/app/teachers/0000.jpg';" data-toggle="tooltip" data-placement="top" title="click to upload image" class="profile_pic rspimg shadow-sm bg-white rounded" id="imgFileUpload" data-toggle="tooltip" data-placement="top" title="Click To Upload image"></a>
<div class=" col-md-10">
<input type="file" name="profile_pic" id="FileUpload1" style="display: none" />
<span id="spnFilePath"></span>
</div>
</div>
ajax: to preview image in browser.
<script>
$(document).ready(function(){
$(function () {
alert(2);
$("#FileUpload1").change(function () {
var imgControlName = "#imgFileUpload";
readURL(this, imgControlName);
});
function readURL(input, imgControlName) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(imgControlName).attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
var fileupload = $("#FileUpload1");
var image = $("#imgFileUpload");
image.click(function () {
fileupload.click();
});
});
});
</script>

Instead this $destination = 'storage/app/teachers'.'/';
try this $destination = storage_path() . '/app/teachers'.'/';

if ($request->hasFile('profile_pic')) {
$image = $request->file('profile_pic');
$fileName = time() . '.' . $image->getClientOriginalExtension();
$img = Input::make($image->getRealPath());
$img->resize(120, 120, function ($constraint) {
$constraint->aspectRatio();
});
$img->stream(); // <-- Key point
//dd();
Storage::disk('local')->put('/app/teachers'.'/'.$fileName, $img, 'public');
}
try this one

Related

I am send dropzone file through ajax but it show ERROR : "You did not select a file to upload" in Codeigniter 3

View
Image
<!------------------------ Bootstarp Source File ------------------------>
<link rel="stylesheet" href="<?php echo base_url('assets/source_files/bootstrap.min.css');?>" >
<!------------------------ Dropzone Source File ------------------------>
<link rel="stylesheet" href="<?php echo base_url('assets/source_files/dropzone.min.css');?>" >
<label class="form_lable">Select Image </label>
<div class="dropzone-container col-md-6" id="demo-dropzone" >
`your text`
<p >
<div class="dz-default dz-message" >
<div class="dz-icon">
<i class="demo-pli-upload-to-cloud icon-5x"></i>
</div>
<div>
<span class="dz-text">Drop files to upload</span>
<p class="text-sm text-muted">or click to pick manually</p>
</div>
</div>
<div class="fallback">
<input type="file" name="userfile" id="userfile" />
</div>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="submit_btn">Submit</button>
</div>
</form>
">
">
">
$('#demo-dropzone').dropzone({
url:"",
autoProcessQueue: false,
addRemoveLinks: true,
multiple:false,
uploadMultiple:true, // uplaod files in a single request
parallelUploads: 1,
maxFiles: 1,
maxFilesize: 500,
acceptedFiles: ".jpg, .png, .jpeg",
init: function() {
var myDropzone = this;
myDropzone.on('maxfilesexceeded', function(file) {
this.removeAllFiles();
this.addFile(file);
});
this.on("removedfile", function(file) {
});
// Update selector to match your button
$("#submit_btn").click(function(e) {
e.preventDefault();
myDropzone.processQueue();
});
this.on("successmultiple", function(file, response) {
if (response && file) {
console.log(response);
}
});
}
});
# Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Image_upload extends CI_Controller
{
public function index(){
$this->load->view('image_send');
}
`File upload funxction`
public function do_upload(){
$image_name = $_FILES['file']['name'][0];
$target= $_FILES['file']['tmp_name'][0];
$target_file = basename($image_name);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$custom_file=basename(uniqid().'.'.$imageFileType);
if(is_dir('upload_image')){
echo "is present";
}
else{
mkdir('upload_image');
}
$config['upload_path'] = 'upload_image/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name'] = $image_name;
$this->upload->initialize($config);
$this->load->library('upload',$config);
if ($this->upload->do_upload('userfile'))
{
$data = array('upload_data' => $this->upload->data());
print_r($data);
}
else
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
}
}
?>
First of all you need to fix your view to have tag to warp out your input.
<form role="form" id="yourFormId" action="#" method="post" enctype='multipart/form-data'></form>
Second, get your form id and set the ajax like this
var frm = $('#yourFormId');
frm.submit(function (e) {
e.preventDefault();
var form_data = new FormData();
var file_data = $('#yourFileInputID').prop('files')[0];
form_data.append('file', file_data);
$.ajax({
type : "POST",
url : TheUrl,
processData : false,
contentType : false,
cache : false,
data : form_data,
dataType : 'json',
success: function (data) {
//Your Code Goes Here..//
}, error: function () {
// Your Code Goes Here //
}
});
});

Capturing multiple image in Vue Js

I have a problem capturing multiple images to my function in vue and pass to the controller. I am trying to modify my blade file which works well when using just the normal form. I am trying to modify to vue but I have a problem with image section. Please assist me on how to achieve this.
my form:
<label for="">Description</label>
<textarea name="description" class="form-control" v-model="description"> </textarea>
<label for="">Images</label>
<input type="file" #change="fieldChange" class="form-control input-sm" name="images[]"
multiple>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
The vue section
data(){
return {
id:'',
price:'',
title:'',
description:'',
location:'',
images:[],
}
},
methods:{
fieldChange(e){
let selectedFiles=e.target.files;
if(!selectedFiles.length){
return false;
}
for(let i=0;i<selectedFiles.length;i++){
this.images.push(selectedFiles[i]);// am able to console the images
}
},
saveImageData(){
var self=this;
axios.post('/senddata',{
title:this.title,
description:this.description,
location:this.location,
images:this.images.file.name,
price:this.price,
})
},
My Laravel function
public function store(Request $request)
{
$product=Products::create([
'title'=>$request['title'],
'description'=>$request['description'],
'price'=>$request['price'],
'location'=>$request['location']
]);
$images= $request->file('images');
foreach ($images as $image){
$move=$image->move(public_path().'/images2/',$image->getClientOriginalName());
if($move){
$imagedata=Images::create([
'title'=>$image->getClientOriginalName(),
'filename'=>$image->getClientOriginalName()
]);
$product->images()->attach([$imagedata->id]);
}
Here is the working code for vuejs part - https://picupload.netlify.app/
https://github.com/manojkmishra/dw_take5/blob/master/src/components/ImageUploader.vue
Vue part
<template>
<div class="uploader"
#dragenter="OnDragEnter"
#dragleave="OnDragLeave"
#dragover.prevent
#drop="onDrop"
:class="{ dragging: isDragging }">
<div class="upload-control" v-show="images.length">
<label for="file">Select files</label>
<button #click="upload">Upload</button>
</div>
<div v-show="!images.length">
<i class="fa fa-cloud-upload"></i>
<p>Drag your images here</p><div>OR</div>
<div class="file-input">
<label for="file">Select files</label>
<input type="file" id="file" #change="onInputChange" multiple>
</div>
</div>
<div class="images-preview" v-show="images.length">
<div class="img-wrapper" v-for="(image, index) in images" :key="index">
<img :src="image" :alt="`Image Uplaoder ${index}`">
<div class="details">
<span class="name" v-text="files[index].name"></span>
<span class="size" v-text="getFileSize(files[index].size)"> </span>
</div>
</div>
</div>
<div v-show="images.length" class="progress">
<div
class="progress-bar progress-bar-info progress-bar-striped"
role="progressbar" :aria-valuenow="progress"
aria-valuemin="0" aria-valuemax="100"
:style="{ width: progress + '%' }"
>
{{ progress}}%
</div>
</div>
</div>
</template>
<script>
import axios from 'axios'
export default
{ data: () => ({ isDragging: false, dragCount: 0, files: [],images: [] ,progress:0}),
methods: {
OnDragEnter(e) { e.preventDefault();
this.dragCount++;
this.isDragging = true;
return false;
},
OnDragLeave(e) { e.preventDefault();
this.dragCount--;
if (this.dragCount <= 0) this.isDragging = false;
},
onInputChange(e) { const files = e.target.files;
Array.from(files).forEach(file => this.addImage(file));
},
onDrop(e) {console.log('ondrop-evnt e=',e)
e.preventDefault();
e.stopPropagation();
this.isDragging = false;
const files = e.dataTransfer.files;
Array.from(files).forEach(file => this.addImage(file));
},
addImage(file) {console.log('addimage file=',file)
if (!file.type.match('image.*')) { this.$toastr.e(`${file.name} is not an image`);
return;
}
this.files.push(file);
const img = new Image(),
reader = new FileReader();
reader.onload = (e) => this.images.push(e.target.result);
reader.readAsDataURL(file);
console.log('addimage this.images=',this.images)
},
getFileSize(size) { const fSExt = ['Bytes', 'KB', 'MB', 'GB'];
let i = 0;
while(size > 900) { size /= 1024; i++; }
return `${(Math.round(size * 100) / 100)} ${fSExt[i]}`;
},
upload() { //this.progress = '0';
const formData = new FormData();
this.files.forEach(file =>
{ formData.append('images[]', file, file.name); });
console.log('upload triggered FormData=',formData)
// resp=axios.post('http://127.0.0.1:8000/sendemail1',this.formData);
// axios.post('http://127.0.0.1:8000/api/imagesupload', formData,
axios.post('https://uat.oms.dowell.com.au/api/imagesupload', formData,
{onUploadProgress:uploadEvent=>{ this.progress=Math.round(uploadEvent.loaded/uploadEvent.total*100);
console.log('upld prges:'+ Math.round(uploadEvent.loaded/uploadEvent.total*100)+'%')
}
})
//axios.post('https://uat.oms.dowell.com.au/api/imagesupload', formData)
.then(response => {
this.$toastr.s('All images uplaoded successfully');
this.images = [];
this.files = [];
this.progress = 0;
})
.catch(() => {
this.$toastr.e('Could not upload the files!');
this.images = [];
this.files = [];
this.progress = 0;
});
}
}
}
</script>
Another version with vuetify
https://github.com/manojkmishra/take5-front-admin/blob/master/src/components/img/imgup.vue
Here is laravel part
public function imagesupload(Request $request){
if (count($request->images)) {
foreach ($request->images as $image) {
$image->store('images');
}
}
return response()->json(["message" => "Done"]);
}
Another way in laravel is here
https://github.com/manojkmishra/take5-api/blob/master/app/Http/Controllers/PicController.php

codeigniter upload 2 files (images and video ) in separate field

Hi i am new in codeigniter , I want to upload image and video in same form with different field. i did but it store either one. last one is stored like video.
<div id="file-upload" class="form-fields">
<div class="new_Btn"><i title="Upload Image" class="fa fa-cloud-upload" aria-hidden="true"></i><span>Upload Image</span></div>
<input id="html_btn" type="file" id="fileToUpload" name="fileToUpload" />
</div>
<div id="file-upload" class="form-fields">
<div class="new_Btn"><i title="Upload Image" class="fa fa-cloud-upload" aria-hidden="true"></i><span>Upload Video</span></div>
<input id="html_btn" type="file" id="videoToUpload" name="videoToUpload" />
</div>
And my controller is
public function videoupdate() {
$data['user_data'] = $this->session->userdata('user_logged_in');
if (($this->session->flashdata('success')))
$data['success'] = $this->session->flashdata('success');
else
$data['error'] = $this->session->flashdata('error');
if (!empty($data['user_data']['user_id'])) {
$title = $_POST['title'];
$description = htmlentities($_POST['description']);
$target_dir = './cms/uploads/blog/video3/';
$temp = explode('.', $_FILES['fileToUpload']['name']);
$video = explode('.', $_FILES['videoToUpload']['name']);
if (!empty($_FILES['fileToUpload']['name'])) {
$newfilename = round(microtime(true)) . '.' . end($temp);
} else {
$newfilename = "";
}
if (!empty($_FILES['videoToUpload']['name'])) {
$videofilename = round(microtime(true)) . '.' . end($video);
} else {
$videofilename = "";
}
move_uploaded_file($_FILES['fileToUpload']['tmp_name'], './cms/uploads/blog/video3/' . $newfilename);
move_uploaded_file($_FILES['videoToUpload']['tmp_name'], './cms/uploads/blog/video3/' . $videofilename);
$createddate = date('Y-m-d H:i:s');
$ipaddress = $_SERVER['REMOTE_ADDR'];
$status = $this->microblog_model->insertBlogvideo($title, $description, $newfilename, $videofilename, $data['user_data']['user_id'], $createddate, $ipaddress);
I found your code for upload files is working fine. As I check it in separate php file:
<pre>
<?php
if(isset($_POST)){
$temp = explode('.', $_FILES['fileToUpload']['name']);
$video = explode('.', $_FILES['videoToUpload']['name']);
try{
//upload image
if (!empty($_FILES['fileToUpload']['name'])) {
$newfilename = round(microtime(true)) . '.' . end($temp);
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], './uploads/' . $newfilename)){
echo "Image Uploaded<br/>";
}
}
//upload video
if (!empty($_FILES['videoToUpload']['name'])) {
$videofilename = round(microtime(true)) . '.' . end($video);
if(move_uploaded_file($_FILES['videoToUpload']['tmp_name'], './uploads/' . $videofilename)){
echo "Video Uploaded<br/>";
}
}
}catch(Exception $e){
print_r($e);
}
}
?>
</pre>
<form method="post" enctype="multipart/form-data">
<div id="file-upload" class="form-fields">
<div class="new_Btn"><i title="Upload Image" class="fa fa-cloud-upload" aria-hidden="true"></i><span>Upload Image</span></div>
<input id="html_btn" type="file" id="fileToUpload" name="fileToUpload" />
</div>
<div id="file-upload" class="form-fields">
<div class="new_Btn"><i title="Upload Image" class="fa fa-cloud-upload" aria-hidden="true"></i><span>Upload Video</span></div>
<input id="html_btn" type="file" id="videoToUpload" name="videoToUpload" />
</div>
<input type="submit" name="submit">
</form>
You should check the size of video you are trying to upload and the maximum upload size allowed. I hope this will help. Because I checked it multiple times with many images and videos and found it is working fine.

Upload Image in Vue Component with Laravel

I am making a simple website that has a feature to upload images. I tried it Laravel way which I made it in blade template and it works fine. Now I am trying to make it inside Vue Components
Here's my Create.vue
<template>
<div>
<div class="row">
<input type="hidden" name="_token" :value="csrf">
<div class="col-md-5">
<div class="detail-container">
<label for="title">Book Title:</label>
<input type="text" name="title" id="title" v-model="book_title" class="form-control">
</div>
<div class="detail-container">
<label for="title">Book Description:</label>
<textarea type="text" name="description" id="description" v-model="book_description" class="form-control" rows="5"></textarea>
</div>
<div class="detail-container">
<label for="title">Tags:</label>
<multiselect v-model="tags" :show-labels="false" name="selected_tags" :hide-selected="true" tag-placeholder="Add this as new tag" placeholder="Search or add a tag" label="name" track-by="id" :options="tagsObject" :multiple="true" :taggable="true" #tag="addTag" #input="selectTags">
<template slot="selection" slot-scope="tags"></template>
</multiselect>
</div>
</div>
<div class="col-md-7">
<!-- BOOK COVER WILL GO HERE -->
<div class="detail-container">
<label>Book Cover:</label>
<input type="file" class="form-control-file" id="book_cover" name="selected_cover" #change="onFileChange">
<small id="fileHelp" class="form-text text-muted">After you select your desired cover, it will show the preview of the photo below.</small>
<div id="preview">
<img v-if="url" :src="url" height="281" width="180" />
</div>
</div>
</div>
<div class="detail-container" style="margin-top: 20px;">
<button class="btn btn-primary" #click="saveBook()">Next</button>
</div>
</div>
</div>
</template>
<script>
import Multiselect from 'vue-multiselect'
// register globally
Vue.component('multiselect', Multiselect)
export default {
// OR register locally
components: { Multiselect },
data () {
return {
csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
url: null,
selected_cover: null,
tags: [],
tagsObject: [],
selected_tags: [],
book_title: '',
book_description: ''
}
},
methods: {
getTags() {
let vm = this;
axios.get('/admin/getTags').then(function(result){
let data = result.data;
for(let i in data) {
vm.tagsObject.push({id: data[i].id, name: data[i].name});
}
});
},
addTag (newTag) {
const tag = {
name: newTag,
id: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000))
}
this.tagsObject.push(tag);
this.tags.push(tag);
},
selectTags(value) {
this.selected_tags = value.map(a=>a.id);
},
onFileChange(e) {
const file = e.target.files[0];
this.url = URL.createObjectURL(file);
this.selected_cover = file;
},
saveBook() {
const fd = new FormData();
fd.append('image', this.selected_cover, this.selected_cover.name)
console.log(this.selected_cover);
var book_details = {
'title': this.book_title,
'description': this.book_description,
'book_cover': this.selected_cover,
'tags': this.selected_tags
};
axios.post('/admin/saveBook', book_details).then(function(result){
console.log('done')
})
}
},
created() {
this.getTags();
}
}
</script>
<!-- New step!
Add Multiselect CSS. Can be added as a static asset or inside a component. -->
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
and here's my controller
public function store(Request $request)
{
$this->validate(request(), [
'title' => 'required|min:5',
'description' => 'required|min:10',
'book_cover' => 'required|image|mimes:jpeg,jpg,png|max:10000'
]);
// File Upload
if($request->hasFile('book_cover')) {
$fileNameWithExt = $request->file('book_cover')->getClientOriginalName();
// GET FILE NAME
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
// GET EXTENSION
$extension = $request->file('book_cover')->getClientOriginalExtension();
// File Unique Name
$fileNameToStore = $filename. '_'. time().'.'.$extension;
$path = $request->file('book_cover')->storeAs('public/book_covers', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
$book = new Book;
$book->title = request('title');
$book->description = request('description');
$book->book_cover = $fileNameToStore;
$book->save();
$book->tags()->sync($request->tags, false);
return back()->with('success', 'Book Created Successfully!');
}
I never touched my controller because this is what I used when I do this feature in Laravel Way but when I save it, the details are being saved but the image is not uploading instead it saves noimage.jpg in the database. Does anyone know what I am doing wrong?
i tried to add this part const fd = new FormData(); in book_details but when i console.log(fd) it returned no data.
you should pass the fd object and not the book_details in your POST request.
you could do it something like this.
onFileChange(e) {
const file = e.target.files[0];
// this.url = URL.createObjectURL(file);
this.selected_cover = file;
},
saveBook() {
const fd = new FormData();
fd.append('image', this.selected_cover)
fd.append('title', this.book_title)
fd.append('description', this.book_description)
fd.append('book_cover', URL.createObjectURL(this.selected_cover))
fd.append('tags', this.selected_tags)
axios.post('/admin/saveBook', fd).then(function(result){
console.log('done')
})
}
and also, you can't just console.log the fd in the console. what you can do instead is something like this
for (var pair of fd.entries()) {
console.log(pair[0]+ ', ' + pair[1]);
}
FormData is a special type of object which is not stringifyable and cannot just be printed out using console.log. (link)

Upload image without form action using dropzone in codeigniter

Upload image without form action using dropzone in CodeIgniter. I need to upload an image without the form action in dropzone. that means, there are one form, dropzone image and other fields are in the form. First when we selecting an image, automatically upload the image and save in the database. And add other fields then submit the form action.
you can Upload image using AJAX with button but a button must be under the form tag with id
View
<form action="<?php echo SURL; ?>admin/registered_students/" id="file_completion_form" class="form-horizontal" method="post" enctype="multipart/form-data">
<td>
<input type="file" data-validation="" style="display: inline" name="undertaking" id="undertaking" value="" placeholder="" multiple="">
</td>
<td>
<input type="hidden" id="student_id" name="student_id" value="<?=$student_id;?>">
<button type="button" class="btn btn-info chk2" id="upload_undertaking">
<i class="fa fa-upload"></i>
</button>
</td>
<td>
<span class="alert" style="display: none" id="msg">Updated</span>
</td>
<td id="download_undertaking">
<a href="<?php echo SURL.'file/download/'.$files[0]['undertaking'];?>">
<button type="button" class="btn btn-info chk2" id=""><i class="fa fa-download"></i></button>
</a>
</td>
</form>
JS
$('#upload_undertaking').click(function(e)
{
e.preventDefault();
var data = new FormData();
var form_data = $('#file_completion_form').serializeArray();
$.each(form_data, function (key, input)
{
data.append(input.name, input.value);
});
//input quatation
var quotation_wip = $('input[name="undertaking"]')[0].files;
if(quotation_wip.length>0)
{
for (var i = 0; i < quotation_wip.length; i++)
{
data.append("undertaking[]", quotation_wip[i]);
}
}
else
{
return 0;
exit;
}
data.append('key', 'value');
var student_id = $('#student_id').val();
$.ajax(
{
url:URL+'file_completion/'+student_id,
type:'POST',
data:data,
cache:false,
contentType: false,
processData: false,
success:function(data)
{
if(data==2)
{
window.location.href=URL+'index/'+student_id;
}
else
{
var obj = jQuery.parseJSON(data);
// alert( obj.undertaking );
$("#undertaking span").html(obj.undertaking);
$("#download_undertaking").html('<button type="button" class="btn btn-info chk2" id=""><i class="fa fa-upload"></i></button>');
$("#msg").show();
setTimeout(function()
{
$("#msg").hide();
},
10000);
}
}
});
});
Controller
public function file_completion1($student_id='',$document_name='')
{
// if($this->input->post('student_id'))
// {
// echo $this->input->post($student_id);
// echo($student_id).'-';
// echo($document_name);
// exit();
$filename=array();
if(count($_FILES['copy_of_paid_fee_challan']['name']) > 0 && $_FILES['copy_of_paid_fee_challan']['name'] !='')
{
$files = $_FILES['copy_of_paid_fee_challan'];
$count = count($_FILES['copy_of_paid_fee_challan']['name']);
//echo $_FILES['file']['name'];exit();
for($i=0; $i<$count;$i++)
{
$config = array();
$projects_folder_path = './assets/uploads/';
$thumb = $projects_folder_path . 'thumb';
$_FILES['copy_of_paid_fee_challan']['name'] = $files['name'][$i];
$_FILES['copy_of_paid_fee_challan']['type'] = $files['type'][$i];
$_FILES['copy_of_paid_fee_challan']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['copy_of_paid_fee_challan']['error'] = $files['error'][$i];
$_FILES['copy_of_paid_fee_challan']['size'] = $files['size'][$i];
// $file_ext = ltrim(strtolower(strrchr($_FILES['copy_of_paid_fee_challan']['name'],'.')),'.');
// $file_name = 'oppein-'.date('YmdGis').'.'.$file_ext;
$config['upload_path'] = $projects_folder_path;
$config['allowed_types'] = '*';
$config['encrypt_name'] = TRUE;
$config['overwrite'] = TRUE;
$config['file_name'] = $_FILES['copy_of_paid_fee_challan']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if(!$this->upload->do_upload('copy_of_paid_fee_challan'))
{
$error_file_arr = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('err_message', $error_file_arr['error']);
$r=2;
echo json_encode($r);
exit();
}
else
{
$data['delete_record'] = $this->Common_model->select_single_records('uploads',$where=array('student_id'=>$student_id));
if(file_exists($projects_folder_path.$data['delete_record']['undertaking']))
{
unlink($projects_folder_path.$data['delete_record']['undertaking']);
}
$data_image_upload = array('upload_image_data' => $this->upload->data());
$image_name =$data_image_upload['upload_image_data']['file_name'];
$full_path = $data_image_upload['upload_image_data']['full_path'];
// ------------------------------------------------------------------------
$this->load->library('image_lib');
$config['image_library'] = 'GD2';
$config['source_image'] = './assets/uploads/' . $image_name;
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'auto';
$config['quality'] = 70;
$config['width'] = 1024;
$config['height'] = 768;
$config['new_image'] = './assets/uploads/' . $image_name;
$this->image_lib->initialize($config);
$this->image_lib->resize();
// ------------------------------------------------------------------------
}
$filename[] = $image_name;
} // end for loop
}
foreach ($filename as $key => $value)
{
$insert_image=array(
'copy_of_paid_fee_challan'=> $value,
// 'student_id' => $student_id,
// 'stage_id' => $stage_id,
'update_date' => date("Y-m-d g:i:s"),
// 'category_status' => 1,
// 'user_id' =>$this->session->userdata('user_id'),
);
// echo "<pre>";
// print_r ($insert_image);
// echo "</pre>";
// exit();
$add_image = $this->Common_model->update_table('uploads',$where=array('student_id'=>$student_id),$insert_image);
}
if ($add_image)
{
$record = $this->Common_model->select_single_records('uploads',$where=array('student_id'=>$student_id));
echo json_encode($record);
}
// }
// else
// {
// $data['active']='registered_students';
// $this->load->view('admin/header',$data);
// $data['student_id']=$student_id;
// $data['error']='';
// $this->load->view('registration/file_completion',$data);
// $this->load->view('admin/footer',$data);
// }
}

Resources