Before you judge me please know that I am not a big pro and just trying to learn how to do things here.
I am trying to create a mailing form with multiple attachments
form code
<div class="file-upload-wrapper">
<label class="file-field" data-max-files="6">
<input type="file" name="photos[]" multiple>
<span>Drag your files here or click to select your files <span>.jpg, .png and .pdf</span></span>
</label>
<div class="uploaded-files"></div>
</div>
js/jQuery code
var photos = [];
var data;
$(document).ready ( function() {
//Documnet Upload Script//
function fileUpload(obj){
var dropZone = obj.find('.file-field');
var fileInput = dropZone.find('input[type="file"]');
var filesBeen = obj.find('.uploaded-files');
var maxFiles = Number(dropZone.attr('data-max-files'));
function highlightDropZone(e){
if(e.type == 'dragover') dropZone.addClass('highlighted');
else dropZone.removeClass('highlighted');
e.preventDefault();
return false;
}
function filesDropped(e){
highlightDropZone(e);
var files = e.target.files || e.dataTransfer.files;
for(var i = 0, file; file = files[i]; i++) {
if(file.size <= 3000000 && (file.type == "application/pdf" || file.type == "image/jpg" || file.type == "image/jpeg" ||file.type == "image/png")) {
photos.push(file);
if (file.type == "application/pdf") {
var uploaded = filesBeen.prepend('<div><div><img src="images/adobe-acrobat-pdf-file-512.png"></div><span></span></div>');
uploaded.find('span').click(function () {
$(this).closest('div').animate({width: 0, height: 0}, 200, function () {
$(this).remove()
});
});
} else {
var fReader = new FileReader();
fReader.onloadend = (function(f){
return function() {
if (maxFiles > Number(filesBeen.children('div').length)) {
var uploaded = filesBeen.prepend('<div><div><img src="' + this.result + '"></div><p><span>' + f.name + '</span></p><span></span></div>');
uploaded.find('span').click(function () {
var me = $(this);
$(this).closest('div').animate({width: 0, height: 0}, 200, function () {
$(this).remove();
me.unbind('click');
});
});
}
}
})(file);
fReader.readAsDataURL(file);
}
}else {
window.alert("The size of the file is more than 3Mb or format is not supported.");
}
}
console.log(photos);
}
dropZone.get(0).addEventListener('dragover', highlightDropZone);
dropZone.get(0).addEventListener('dragleave', highlightDropZone);
dropZone.get(0).addEventListener('drop', filesDropped);
fileInput.get(0).addEventListener('change', filesDropped);
}
$('.file-upload-wrapper').each(function(){
new fileUpload($(this));
});
$('.submit-form').click(function(e) {
e.preventDefault();
// Store values in variables
var form = $('form[name="contact-form"]');
var ip = form.find('input[name=ip]');
var httpref = form.find('input[name=httpref]');
var httpagent = form.find('input[name=httpagent]');
var name = form.find('input[name=name]');
var email = form.find('input[name=email]');
var phone = form.find('input[name=phone]');
var message = form.find('textarea[name=message]');
var submitted = form.find('input[name=submitted]');
var visitor = form.find('input[name=visitor]');
var emails = form.find('input[name=email]').val();
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
if (validateEmail(emails)) {
// Organize data
data = new FormData();
data.append('ip', ip.val());
data.append('httpref', httpref.val());
data.append('httpagent', httpagent.val());
data.append('name', name.val());
data.append('email', email.val());
data.append('phone', phone.val());
data.append('message', message.val());
data.append('submitted', submitted.val());
data.append('visitor', visitor.val());
for(var i = 0; i < photos.length; i++){
data.append('file'+i, photos[i]);
}
var request = $.ajax({
type: "POST",
dataType: 'script',
url: "/includes/sendConatctform.php",
data: data,
cache: false,
contentType: false,
processData: false,
success: function (html) {
if (html == "true") {
form.find('.email-sent').fadeIn(500).delay(4000).fadeOut(500);
} else {
form.find('.email-error').fadeIn(500).delay(4000).fadeOut(500);
}
},
error: function (jqXHR, textStatus, error) {
alert("Form Error: " + error);
}
});
} else {
form.find('.email-results').fadeIn(500).delay(4000).fadeOut(500);
}
return false;
});
});
What I am trying to do is to receive the attachments in my PHP file for further proceedings.
php code
$message = "Date: $todayis \r\n";
$message .= "From: $name ($email) \r\n";
$message .= "Phone: $phone \r\n";
$message .= "Subject: $subject \r\n";
$message .= "Message: $userMessage \r\n";
$message .= "IP Address: $ip \r\n";
$message .= "Browser Info: $httpagent \r\n";
$message .= "Referral: $httpref \r\n";
foreach($_FILES['photos']['name'] as $file){
$message .= "Attachments:" .$file['filename'];
}
I have tried the suggestion that I have found here Send multiple file attachments to php file using ajax
but it did not help with my situation.
can you please advise?
All help is appreciated
Thank you in advance
Since in your php code you are iterating over $_FILES['photos'], then you should change in your js code this:
data.append('file'+i, photos[i]);
to
data.append('photos[]', photos[i]);
Update:
Also, in your php code change $file['filename'] here:
foreach($_FILES['photos']['name'] as $file){
$message .= "Attachments:" .$file['filename'];
}
to just $file:
foreach($_FILES['photos']['name'] as $file){
$message .= "Attachments:" . $file;
}
Related
I have a function called function getContactsToForm();
This function runs on a div row called results that holds the values from my sql. On click each row is supposed to load this function grab the data from li[0] and pass it on to the rest of the function.
I seem to be getting it to work all right, however the Li's show up empty on my console log even though the table is populated. I assume that means that the sequencing is wrong.
Previously I had a working sample that had everything it table rows. The original function commented out would use the Tr tags and grab the value. The function was called within the getContacts() function and it all worked well, with the LI I am having trouble. Any thoughts?
functions.js
// JavaScript Document
//formoverlay
function formSubmit() {
$.ajax({
type: 'POST',
url: 'contactsinsert.php',
data: $('#frmBox').serialize(),
success: function(response) {
$('#success').html(response);
}
});
var form = document.getElementById('frmBox').reset();
window.location.reload();
return false;
}
$(document).ready(function() {
$('#srchbtn').click(function start() {
getContacts();
});
});
function getContacts() {
var txtsearch = $('#txtsearch').val();
$.ajax({
url: 'contactstable.php',
type: "POST",
//dataType: "json",
data: ({
txtsearch: txtsearch
}),
success: function(response) {
$('#displayContacts').html(response);
//addRowHandlers();
//getContactsToForm();
}
});
}
window.onload = getContacts();
/*function addRowHandlers() {
console.log("hi");
var table = document.getElementById("resultstable");
var rows = table.getElementsByTagName("li");
console.log(rows[0]);
for (i = 0; i < rows.length; i++) {
var currentRow = table.rows[i];
console.log(currentRow);
var createClickHandler = function(row) {
return function() {
*/
function getContactsToForm() {
var table = document.getElementById("resultstable");
var rows = table.getElementsByTagName("ul")['results'];
console.log(rows);
var lis = table.getElementsByTagName('li')[0];
console.log(lis);
var id = lis.innerHTML;
console.log(id);
//alert("id:" +id);
document.getElementById("id").value = id;
$.ajax({
url: "inputtest.php",
success: function(result) {
var frm = document.getElementById("frmBox2");
var ID = document.getElementById("id").value;
if (/\S/.test(ID)) {
ajax_request(this.action, {
"action": "fetch",
"ID": ID
}, process_response);
} else {
alert("No ID supplied");
}
function ajax_request(url, data, callback) {
var i, parts, xhr;
// if data is an object, unroll as HTTP post data (a=1&b=2&c=3 etc.)
if (typeof data == "object") {
parts = [];
for (i in data) {
parts.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
}
data = parts.join("&");
}
// create an XML HTTP Request object
xhr = new XMLHttpRequest();
if (xhr) {
// set a handler for changes in ready state
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// check for HTTP status of OK
if (xhr.status == 200) {
try {
callback(JSON.parse(xhr.responseText));
} catch (e) {
console.log(xhr.responseText); // for debug
alert("AJAX request incomplete:\n" + e.toString());
}
} else {
alert("AJAX request failed: " + xhr.status);
}
}
};
// open connection and send payload
xhr.open("GET", "inputtest.php" + "?" + data, true);
xhr.send(null);
}
}
/**
* process the response, populating the form fields from the JSON data
* #param {Object} response the JSON data parsed into an object
*/
function process_response(response) {
var frm = document.getElementById("frmBox2");
var i;
console.dir(response); // for debug
for (i in response) {
if (i in frm.elements) {
frm.elements[i].value = response[i];
}
}
}
}
});
};
// currentRow.onclick = createClickHandler(currentRow);
// }
// }
//window.onload = addRowHandlers();
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
window.location.reload();
}
function openCon() {
document.getElementById("conNav").style.width = "100%";
}
function closeCon() {
document.getElementById("conNav").style.width = "0%";
var form = document.getElementById('frmBox').reset();
}
function enablebuttons() {
document.getElementById("insert").disabled = false;
}
contactstable.php (calls the mysql and receives contacts)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
include_once "iud.php";
$arrayval = array();
$search=$_POST['txtsearch'];
$search1 = explode(" ", $search);
array_push($arrayval, $search1);
foreach ($arrayval as $val){
$orIndex = checkOr($val);
if(empty($orIndex)){
$resultstable = getResults($val);
$resultstable1 = buildTable($resultstable);
print($resultstable1);
}else{
print"there is an or here";
$resultstable = getResults($orIndex);
$resultstable1 = buildTable($resultstable);
print($resultstable1);
}
}
buildTable($resultstable);
/*if (empty($orIndex)){
print "no or";
$resultstable = getResults($val);
$resultstable1 = buildTable($resultstable);
print $resultstable1;
function getResults($array){
include_once "iud.php";
$db = connectDatabase();
$totalResults = array();
$length = count($array);
for ($i = 0; $i < $length; $i++){
$outputDisplay = "";
$myrowcount = 0;
$sql_statement = "SELECT id, firstname, lastname, pcat, position, state ";
//, congroup, cattype, company, position, email, website, phone, mphone, wphone, fax, add1, add2, city, state, zip, country, reference, entrydate, enteredby, notes ";
$sql_statement .= "FROM contacts ";
$sql_statement .= "WHERE (firstname LIKE '%$array[$i]%' or lastname LIKE '%$array[$i]%')";
$sql_statement .= "ORDER BY lastname, firstname";
$sqlResults = selectResults($db, $sql_statement);
$error_or_rows = $sqlResults[0];
if (substr($error_or_rows, 0 , 5) == 'ERROR')
{
$outputDisplay .= "<br />Error on DB";
$outputDisplay .= $error_or_rows;
} else {
$totalResults = array_merge($totalResults, $sqlResults);
//$totalResults = array_map("unserialize", array_unique(array_map("serialize", $totalResults)));
$arraySize = $error_or_rows;
}
}
//return $totalResults;
//print $arraySize;
//print_r($error_or_rows);
return $totalResults;
}
function buildTable($totalResults){
include_once "iud.php";
$outputDisplay = "";
//$outputDisplay .= '<table id="resultstable" style="overflow-x:auto;">';
//$outputDisplay .= '<tr><th align="left">ID</th><th align="left" width="30%">First Name</th><th align="left" width="30%">Last Name</th><th align="left" width="30%">Pages Category</th><th align="left" width="30%">Position</th><th align="left" width="30%">state</th></tr>';
$outputDisplay .= '<div id="resultstable">';
$outputDisplay .= '<div id="headers">';
$outputDisplay .= '<ul id="headers">';
$myrowcount = 0;
for ($i=0; $i < count($totalResults); $i++)
{
$myrowcount++;
$contactid = $totalResults[$i]['id'];
$firstname = $totalResults[$i]['firstname'];
$lastname = $totalResults[$i]['lastname'];
$pcat = $totalResults[$i]['pcat'];
$position = $totalResults[$i]['position'];
$state = $totalResults[$i]['state'];
$outputDisplay .= '<ul id="results">';
$outputDisplay .='<li>'.$contactid.'</li>';
$outputDisplay .= '<li><span style="font-size:10px;cursor:pointer" onclick="openCon();getContactsToForm();">'.$firstname.'</span></li>';
$outputDisplay .= '<li><span style="font-size:10px;cursor:pointer" onclick="openCon()">'.$lastname.'</span></li>';
$outputDisplay .= '<li><span style="font-size:10px;cursor:pointer" onclick="openCon()">'.$pcat.'</span></li>';
$outputDisplay .= '<li><span style="font-size:10px;cursor:pointer" onclick="openCon()">'.$position.'</span></li>';
$outputDisplay .= '<li><span style="font-size:10px;cursor:pointer" onclick="openCon()">'.$state.'</span></li>';
$outputDisplay .= '</ul>';
//echo $myrowcount;
}
$outputDisplay .= "</div>";
return $outputDisplay;
}
function checkOr($searchArray){
if (in_array("OR",$searchArray)){
$orPos = array_search("OR", $searchArray);
//$surrVal =array();
//$surrVal = array(--$orPos, ++$orPos);
if (!empty($orPos)){
$surrVal = "";
$surrVal = --$orPos;
$orValArray = array();
array_push($orValArray,$searchArray[$surrVal]);
$surrVal = $orPos+2;
array_push($orValArray,$searchArray[$surrVal]);
return $orValArray;
}
}
}
The results I get are:
209AnisBakerDC
but from the console side:
I am attempting to upload multiple images from AJAX to PHP. Here's a run down of what I have so far.
HTML
<form>
<input class="images" type="file">
</form>
There could be more than one input field if the user has multiple images to upload.
Javascript
var imageObject = GetAllFiles($('.images'));
function GetAllFiles(_selector)
{
var newObject = {};
for (var i = 0; i < $(_selector).length; i++)
{
var elem = $(_selector)[i];
newObject[i] = $(elem).files;
}
return newObject;
}
$(document).on('click', '#submit', function() {
var _data = JSON.stringify(imageObject);
$.post('upload.php', { action: 'ImageUpload', data: _data }, function (e){
alert(e);
});
)};
Send data via AJAX after conversion to JSON
PHP
if(isset($_POST['action']))
{
$action = $_POST['action'];
switch($action)
{
case 'ImageUpload' : ImageUpload($_POST['data']); break;
}
}
function ImageUpload($jsonData)
{
$images = json_decode($jsonData);
foreach($images as $image)
{
$directory = "../images/maschine/";
$target_file = $directory . basename($_FILES[$image])['name'];
if (move_uploaded_file($_FILES[$image]["tmp_name"], $target_file))
{
echo('Success');
} else
{
echo('Failure');
}
}
}
Add id in the file input first, and remember the enctype='multipart/form-data' in form.
<input class="images" name="file[]" type="file" multiple>
after that in the script
<script>
$('YoursubmitbuttonclassorId').click(function() {
var filedata = document.getElementsByName("file"),
formdata = false;
if (window.FormData) {
formdata = new FormData();
}
var i = 0, len = filedata.files.length, img, reader, file;
for (; i < len; i++) {
file = filedata.files[i];
if (window.FileReader) {
reader = new FileReader();
reader.onloadend = function(e) {
showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("file", file);
}
}
if (formdata) {
$.ajax({
url: "/path to upload/",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function(res) {
},
error: function(res) {
}
});
}
});
</script>
In the php file
<?php
for($i=0; $i<count($_FILES['file']['name']); $i++){
$target_path = "uploads/";
$ext = explode('.', basename( $_FILES['file']['name'][$i]));
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext)-1];
if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
echo "The file has been uploaded successfully <br />";
} else{
echo "There was an error uploading the file, please try again! <br
/>";
}
}
?>
As I was coding I encountered an absolute annoying error when callbacking the responseText from PHP.
Now the issue is that, when I run the fpass.php file, and fill out the data, everything works except when callbacking the responseText, for example if it prints out MAIN_FPASS_USER_NO_MATCH from the PHP file it should change the _('status').innerHTML to a different text of my choice, and not what the PHP printed. Some ideas for what I missed in my code?
JS Script:
function fpass(){
var e = _("email").value;
if(e == ""){
_("status").innerHTML = "Type in your email address</br></br>";
} else {
_("fpassbtn").style.display = "none";
_("status").innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "/fpass.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == 'MAIN_FPASS_SUCCESS'){
_("fpassform").innerHTML = '<h3>Step 2. Check your email inbox in a few minutes</h3><p>You can close this window or tab if you like.</p>';
} else if(ajax.responseText == "MAIN_FPASS_USER_NO_MATCH"){
_("fpassbtn").style.display = "none";
_("status").innerHTML = "Sorry that email address is not in our system";
} else if(ajax.responseText == "MAIN_FPASS_EMAIL_FAILURE"){
_("fpassform").innerHTML = "Mail function failed to execute";
} else if (ajax.responseText == "MAIN_FPASS_EXISTS") {
_("fpassform").innerHTML = "already fpass";
} else {
_("status").innerHTML = ajax.responseText;
}
}
}
}
ajax.send("e="+e);
}
JS Functions:
// getElementById Function
function _(x){
return document.getElementById(x);
}
// emptyElement Function
function emptyElement(x){
_(x).innerHTML = "";
}
Ajax Functions:
function ajaxObj(meth, url){
var x = new XMLHttpRequest();
x.open(meth, url, true);
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//x.send(data);
return x;
}
// END Ajax Object
// Start Ajax Return
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}
}
HTML Code:
<span id="status"></span>
<form id="fpassform" onsubmit="return false;">
<input id="email" type="text" placeholder="Email" onfocus="emptyElement('status')" maxlength="88">
<button id="fpassbtn" onclick="fpass()">Reset</button></br>
</form>
PHP Code:
// AJAX CALLS THIS CODE TO EXECUTE
if(isset($_POST['e'])){
include_once("vendor/db.php");
$e = $mysqli->real_escape_string($_POST['e']);
$usql = "SELECT * FROM users WHERE useremail='$e' AND activated='1' LIMIT 1";
$uresult = $mysqli->query($usql);
$unumrows = $uresult->num_rows;
if($unumrows == 1){
$fpsql = "SELECT * FROM forgotpass WHERE useremail='$e' LIMIT 1";
$fpresult = $mysqli->query($fpsql);
$fpnumrows = $fpresult->num_rows;
if($fpnumrows == 0) {
if($fetch = $uresult->fetch_array(MYSQLI_FETCH_ASSOC)){
$u = $fetch["username"];
$e = $fetch['useremail'];
$pn = $fetch['userphone'];
$fpkey = substr(md5(uniqid($u)), 0, 14);
$sql = "INSERT INTO `forgotpass` (username,useremail,userphone,fpkey)
VALUES ('$u','$e','$pn','$fpkey') ";
if($mysqli->query($sql)) {
$to = "$e";
$from = "auto_responder#yoursite.com";
$headers ="From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$subject ="yoursite Temporary Password";
$msg = 'MSG here';
if(mail($to,$subject,$msg,$headers)) {
echo 'MAIN_FPASS_SUCCESS';
exit();
} else {
echo 'MAIN_FPASS_MAIL_FAILURE';
exit();
}
}
}
} else {
echo 'MAIN_FPASS_EXISTS';
exit();
}
} else {
echo 'MAIN_FPASS_USER_NO_MATCH';
exit();
}
exit();
}
I have music file to upload on database
and from view side I have addmore button for music input type file and I got that music's name like:
music1.mp3,music2.mp3,music3.mp3
After that I explode this above on controller file.
I don't know, is this correct?
$expaudio = explode(',',$audio);
$audioCount = count($expaudio);
if($audioCount == 0){ $audiolist = $audio; }
else{ $audiolist = $expaudio; }
for($i=0; $i<$audioCount; $i++){
//******************************* UPLOAD MUSIC ********************************//
$config['allowed_types'] = 'avi|mpeg|mp3|mp4|3gp|wmv'; //video and audio extension
$config['max_size'] = '40000000';
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
//$video_name = random_string('numeric', 5);
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 10; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
$video_name = $randomString;
$config['file_name'] = $video_name;
$config['upload_path'] = 'Users/'.$data['loginuserpage'].'/music/'.$project_url.'/audio';
//$config['allowed_types'] = 'gif|jpg|jpeg|png|doc|docx|ppt|pptx|pdf|txt|avi|mpeg|mp3|mp4|3gp|wmv'; // Image , video and audio
$this->load->library('upload', $config);
if (!$this->upload->do_upload($audiolist[$i]))
{
$error = array('error' => $this->upload->display_errors());
$vid_url = '';
print_r($this->upload->display_errors());
}
else
{
$upload_data = $this->upload->data();
$aud_name = $upload_data['file_name'];
$aud_type = $upload_data['file_type'];
$aud_url = $baseurl.$config['upload_path']."/".$aud_name;
}
//******************************* UPLOAD MUSIC ********************************//
}
My Ajax file
$("input[name='audio[]']").change(function()
{
var temp =[]
$("input[name='audio[]']").each(function(i, selected){
texts = $(selected).val()
temp.push(texts);
var jcat1 = temp.join(",");
alert(jcat1);
$('#audioarr').val(jcat1);
});
});
$('form#music').submit(function(e)
{
e.preventDefault();
var form = $(this);
/*var purl = form.find('#project_url').val();
if (purl.length < 8) {
$('p#purl').html('Please enter a url without space and specialchar');
return false;
}*/
var video = form.find('#video').val();
var trailer = form.find('#trailer').val();
dataString = $("form#music").serialize();
$.ajax({
url: '<?php echo base_url('video/creations/createmusic'); ?>',
type: "POST",
data: dataString,
data: new FormData(this),
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false,
success: function(data) { $("#success").html(data); }
});
});
You don't need to use for loop for uploading multiple files.
Since you are storing all file details in single array, use can use
$this->upload->do_upload('audio'); // input file name
You can access uploaded file details from
$data = $this->upload->data();
foreach($data as $audio) {
`// code goes here...`
}
im sorry mr im try this code for upload with angular in codeigniter but file and data not insert to database and file not upload, :)
please corectly im no find that tutorial in google please..
$postdata = file_get_contents("php://input");
$data = json_decode($postdata);
$config['upload_path'] = 'assets/img/img_berita/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if( ! $this->upload->do_upload($data($_FILES['file'])) ) {
$this->set_model->update_data('berita', array('gambar' => $data['file']['name']), array('id_berita' => $data['id_berita']) );
echo '{"stat" : "Success!"}';
} else {
echo '{"stat" : "Try Again!"}';
}
app.controller('berita_uploadImage', function($scope,$http,$routeParams,$location,Upload) {
$scope.ImageInfo =
$scope.dataInfo = [];
$scope.onFileSelect = function(file) {
//console.log($scope.picFile);
if (!file) return;
console.log(file);
Upload.upload({
method : 'POST',
url : '<?php echo base_url();?>home/dashboard/admin/upload_image_berita',
data : JSON.stringify({'id_berita':$scope.id_berita,file:file}),
}).success(function(data) {
console.log($scope.id_berita);
console.log(file);
console.log(data.stat);
});
}
$scope.id_berita = $routeParams.id_berita;
$http.get('<?php echo base_url(); ?>home/dashboard/admin/getImage_berita/' + $scope.id_berita ).success(function(result) {
$scope.dataInfo = result;
});