I am using Angular in this code to send formData to my upload.php file and then from upload.php, copying file to another Direcrtory and insert its address to MySQL musiclist data base but my code isn't working and not even showing any Error I don't know what to do
Any help would be Appreciable
<body>
<div class="container" ng-app="myapp" ng-controller="cntrl">
<div class="col-md-4">
<input type="file" file-input="files">
</div>
<div class="col-md-6">
<button class="btn btn-info" ng-click="uploadfile()">upload</button>
</div>
</div>
<div class="container" ng-app="myapp" ng-controller="cntrl">
<div class="col-md-4">
<input type="file" file-input="files">
</div>
<div class="col-md-6">
<button class="btn btn-info" ng-click="uploadfile()">upload</button>
</div>
</div>
</body>
</html>
<script>
var app = angular.module("myapp",[]);
app.directive("fileinput", function($parse){
return{
link : function($parse,element,attrs){
element.on("change", function(event){
var files = event.target.files;
$parse(attrs.fileInput).assign(element[0].files);
$scope.apply();
});
}
}
});
app.controller("cntrl",function($scope,$http){
$scope.uploadfile = function(){
var form_data= new FormData();
angular.forEach($scope.files, function(file){
form_data.append('file',file);
});
$http.post('upload.php', form_data,
{
transformRequest: angular.identity,
headers{'Content-Type': undefined ,'Process-Data': false}
}).success(function(response){
alert(response);
});
}
});
upload.php Code is
<?PHP
$connect= mysqli_connect("localhost","root","","musiccloud");
if(!empty($_FILES)){
$path='uploads/'.$_FILES['file'['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'],$path))
{
$Insertquery= "INSERT INTO musiclist(name) VALUES('".$_FILES['file']
['name']."')";
if(mysqli_query($connect,$Insertquery))
{
echo 'file Uploaded';
}
else{
echo 'file Not Uploaded';
}
}
}
else{
echo 'some Error';
}
?>
Related
I created a form upload which contains some inputs but when I submitted the form to ajax, ajax was unable to grap the file name.
I keep on getting Notice: Undefined index: userImage in C:\wamp\www\osun\i_admin\php_action\uploadImage.php on line 14 . userImage is the name of the file
index.php
<?php include('header.php'); ?>
<?php include('top.php'); ?>
<?php include('links.php'); ?>
<section class="content">
<div class="container-fluid">
<div class="block-header">
<h2>Worker of the Month</h2>
</div>
<!-- Basic -->
<div class="row clearfix">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="card">
<div id="error" class="closeit"></div>
<div id="messages"></div>
<div class="body">
<form enctype="multipart/form-data" id="uploadImageForm">
<div class="form-group form-float">
<div class="form-line">
<input type="text" class="form-control" name="name" id="name">
<label class="form-label">Worker's Name</label>
</div>
</div>
<div class="form-group form-float">
<div class="form-line">
<input type="text" class="form-control" name="dept" id="dept">
<label class="form-label">Department</label>
</div>
</div>
<div class="form-group form-float">
<div class="input-group">
<div class="form-line">
<input type="text" data-type="date" id="date" name="date" placeholder="Date" class="form-control datepicker">
</div>
</div>
</div>
<div class="form-group form-float">
<div class="form-line">
<textarea name="description" id="description" cols="30" rows="5" class="form-control no-resize"></textarea>
<label class="form-label">Description</label>
</div>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Photo</label>
<div id="kv-avatar-errors-2" class="center-block" style="width:800px;display:none"></div>
<div class="kv-avatar center-block" style="width:200px">
<input id="avatar-2" name="userImage" type="file" class="file-loading">
</div>
</div>
<div class="form-group" align="center">
<button type="input" name="submit" class="btn btn-success btn-md btn-icon waves-effect" id="btn-submit" ><i class="fa fa-check-square-o"></i> Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- #END# Basic -->
</div>
</section>
<?php include('footer.php'); ?>
uploadimage.php
include('../../includes/functions.php');
if($_POST) {
$valid = array('success' => false, 'messages' => array());
$name = $mysqli->real_escape_string($_POST['name']);// user name
$dept = $mysqli->real_escape_string($_POST['dept']);
$desc = $mysqli->real_escape_string($_POST['description']);// user email
$yr = $mysqli->real_escape_string($_POST['date']);
$fileName = $_FILES['userImage']['name'];
$type = explode('.', $fileName);
$type = $type[count($type) - 1];
$url = '../user_images/' . uniqid(rand()) . '.' . $type;
if(in_array($type, array('gif', 'jpg', 'jpeg', 'png'))) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
if(move_uploaded_file($_FILES['userImage']['tmp_name'], $url)) {
// insert into database
$sql = "INSERT INTO worker_of_the_month (name, dept, description, given, img) VALUES ('$name','$dept','$desc','$yr', '$url')";
if($mysqli->query($sql) === TRUE) {
$valid['success'] = true;
$valid['messages'] = "Successfully Saved.";
}
else {
$valid['success'] = false;
$valid['messages'] = "Error while saving. " . $mysqli->error;
}
$mysqli->close();
}
else {
$valid['success'] = false;
$valid['messages'] = "Error while saving. " . $mysqli->error;
}
}
}
echo json_encode($valid);
// upload the file
}
Ajax.js
$('document').ready(function() {
/* validation */
$("#uploadImageForm").validate({
rules:
{
name:{
required: true
},
dept:{
required: true
},
description:{
required: true
},
date:{
required: true
},
},
messages:
{
name: "Worker name required",
dept: "Worker department name required",
description: "Enter description for this honour.",
date: "Please select date",
},
submitHandler: submitForm
});
/* validation */
/* form submit */
function submitForm()
{
var data = $("#uploadImageForm").serialize();
$.ajax({
type : 'POST',
url : 'php_action/uploadImage.php',
data : data,
beforeSend: function()
{
$("#error").fadeOut();
$("#btn-submit").html('<img src="../img/processing.gif" width="30" /> processing');
},
success : function(data)
{
if(data.success == true)
{
$("#btn-submit").html('<img src="../img/processing.gif" width="30" /> Saving ...');
$("#messages").html('<div class="alert alert-success alert-dismissible" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+
data.messages +
'</div>');
$('#uploadImageForm')[0].reset();
/*setTimeout(' window.location.href = "success.php"; ',4000);*/
}
else{
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-danger"><span class="glyphicon glyphicon-info-sign"></span> '+data+' !</div>');
$("#btn-submit").html('<span class="fa fa-check-square-o"></span> Save');
});
}
}
});
return false;
}
/* form submit */
});
</script>
What am I doing wrong?
You need to use a FormData() to pass files.
Change
var data = $('#uploadImageForm').serialize();
to
var form = $('#uploadImageForm')[0];
var data = new FormData(form);
As #ThisGuyHasTwoThumbs pointed you should set cache, contentType and processData via your ajax call
$.ajax({
cache: false,
processData: false,
contentType: false,
//other ajax parameters
});
You cannot POST files via AJAX like you have your code now.
This is how you can upload files using javascript and way better option:
PHP:
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
'username' => $_REQUEST['username'],
'accountnum' => $_REQUEST['accountnum']
));
echo $json;
?>
HTML:
<!DOCTYPE html>
<!--
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Eric Bidelman (ericbidelman#chromium.org)
-->
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<title>xhr.send(FormData) Example</title>
</head>
<body>
<input type="file" name="afile" id="afile" accept="image/*"/>
<script>
document.querySelector('#afile').addEventListener('change', function(e) {
var file = this.files[0];
var fd = new FormData();
fd.append("afile", file);
// These extra params aren't necessary but show that you can include other data.
fd.append("username", "Groucho");
fd.append("accountnum", 123456);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'handle_file_upload.php', true);
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
var percentComplete = (e.loaded / e.total) * 100;
console.log(percentComplete + '% uploaded');
}
};
xhr.onload = function() {
if (this.status == 200) {
var resp = JSON.parse(this.response);
console.log('Server got:', resp);
var image = document.createElement('img');
image.src = resp.dataUrl;
document.body.appendChild(image);
};
};
xhr.send(fd);
}, false);
</script>
<!--[if IE]>
<script src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
<script>CFInstall.check({mode: 'overlay'});</script>
<![endif]-->
</body>
</html>
Quick example taken from: https://gist.github.com/ebidel/2410898
I have this script that allows me to send data to the database without reloading the page. The form data is sent to file process.php.
At the end of the process, inside the div box of the form is printed a notice that everything went ok
<script type="text/javascript">
$(document).ready(function(){
$(document).on('submit', '.formValidation', function(){
var data = $(this).serialize();
$.ajax({
type : 'POST',
url : 'submit.php',
data : data,
success : function(data){
$(".formValidation").fadeOut(500).hide(function(){
$(".result").fadeIn(500).show(function(){
$(".result").html(data);
});
});
}
});
return false;
});
});
</script>
Page success.php:
foreach( $_POST as $key => $value ) {
$sql = "INSERT INTO tbl_".$key."(nome_".$key.") VALUES ('$value')";
$result = dbQuery($sql);
}
print "ok";
And the div box for the notice <div class="result"></div>
The problem: I have many div box with a form and when I print the notice of success, it happen into all the <div>, because the call notification is always .result
success: function(data){
$(".formValidation").fadeOut(500).hide(function(){
$(".result").fadeIn(500).show(function(){
$(".result").html(data);
});
});
}
What I want: Print the success notice in its own div depending on the form that I sent.
Thanks
EDIT: The html interested
<form id="myform2" class="formValidation" name="myform2" action="" method="post"></form> <!-- this is the form for the <div> in html5 -->
<div class="widget-body">
<div class="widget-main">
<div>
<label for="form-field-select-1">Comune</label>
<select name="comune" class="form-control" id="form-field-select-1" form="myform2">
<option value="">Seleziona...</option>
<?php
$comune = "SELECT * FROM tbl_comune ORDER BY nome_comune ASC";
$result_comune = dbQuery($comune);
if (dbNumRows($result_comune) > 0) {
while($row_comune = dbFetchAssoc($result_comune)) {
extract($row_comune);
?>
<option value="<?php echo $id_comune; ?>"><?php echo $nome_comune; ?></option>
<?php
}
} else {
?>
<option value="">Non ci sono dati</option>
<?php
}
?>
</select>
</div>
<hr>
<div class="widget-body">
<div class="widget-main">
<div>
<input type="text" name="comune" id="comune" value="" placeholder="Aggiungi Comune" form="myform2">
<input type="submit" name="submit" value="Submit" class="btn btn-sm btn-success" form="myform2">
<div class="result"></div>
</div>
</div>
</div>
</div>
</div>
If the form is in a div and the result is next to the form, you can do sibling:
$form.next(".result").html(data);
or elsewhere in the same parent:
$form.parent().find(".result").html(data);
or in your case
$form.find(".result").html(data);
Like this - note I have removed all the unnecessary hiding.
$(function() {
$(document).on('submit', '.formValidation', function(e) {
e.preventDefault();
var data = $(this).serialize();
$form = $(this); // save a pointer to THIS form
$result = $form.find(".result");
$.ajax({
type: 'POST',
url: 'submit.php',
data: data,
success: function(data) {
$result.html(data);
$form.fadeOut(500, function() {
$result.fadeIn(500)
});
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="myform2" class="formValidation" name="myform2" action="" method="post"></form>
<!-- this is the form for the <div> in html5 -->
<div class="widget-body">
<div class="widget-main">
<div>
<label for="form-field-select-1">Comune</label>
<select name="comune" class="form-control" id="form-field-select-1" form="myform2">
<option value="">Seleziona...</option>
</select>
</div>
<hr>
<div class="widget-body">
<div class="widget-main">
<div>
<input type="text" name="comune" id="comune" value="" placeholder="Aggiungi Comune" form="myform2">
<input type="submit" name="submit" value="Submit" class="btn btn-sm btn-success" form="myform2">
<div class="result"></div>
</div>
</div>
</div>
</div>
</div>
<?php
session_start();
if(isset($_SESSION['user']))
{
?>
<head>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="vali/css/bootstrapValidator.css"/>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootswatch.js"></script>
<script type="text/javascript" src="vali/js/bootstrapValidator.js"> </script>
<script src="../SnapClient/gui.js"></script>
<script src="../SnapClient/cloud.js"></script>
<script src="../SnapClient/index.html"></script>
</head>
<body>
<br><br><br><br>
<!-- Fixed navbar -->
<?php include("header.html");?>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h4> <img alt="" height="50" width="80"/> Account Settings </h4>
</div>
<div class="panel-body">
<div class="col-ms-8"><hr><center><h5>Pick Your Profile Picture</h5></center>
<div class="well">
<form class="form-horizontal" id="fileForm" method="post" action="registrationupdate3.php" enctype="multipart/form-data" >
<fieldset>
<div class="form-group">
<label for="image" class="col-lg-3 control-label">Profile Picture<span style="color:red;">*</label>
<div class="col-lg-6">
<input type="file" class="form-control" name="image" />
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-3">
<button class="btn btn-primary" id="imageupload" name="imageupload" >Update</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#fileForm')
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
image: {
validators: {
file: {
extension: 'jpeg,png',
type: 'image/jpeg,image/png',
maxSize: 100 * 100,
message: 'The selected file is not valid'
}
}
}
}
})
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
$.post($form.attr('action'), $form.serialize(), function(result) {
if(result=="success")
{
alert(result);
}
else
{
alert(result);
}
}, 'json');
});
});
</script>
<?php include("footer.html");?>
</body>
</html>
<?php
} else {
header("Location:index.html");
}
?>
php file
<?php
session_start();
include 'db_connection.php';
if(is_uploaded_file($_FILES['image']['tmp_name'])) {
$prfimage= addslashes(file_get_contents($_FILES['userImage'] ['tmp_name']));
$username = $_SESSION['user'];
$query= mysql_query("UPDATE userdetails set profileimage='{$prfimage}' WHERE username='".$username."'");
echo $query;
}
else
{
echo "the image file is empty";
}
?>
Always it is showing empty(selected image file is empty). anyone knows why? please help me if anyone knows it. i need to store the user selectd image file in mysql. and i used bootstrapvalidator for validating the image input. i checked without bootstrapvalidator the image is stored in mysql and everything is working fine but if i use bootstrapvalidator it is showing undefined index
I've been working with Ajax to send and upload files, everything worked perfect, I could upload both photos and files with no problem, but now it just don't work for .pdf files.
This is why I got, from my jQuery file:
function uploadImage(){
$('#file').change(function(){
var file = this.files[0]
if(file){
$('.alert.alert-danger').hide();
$('#filename').text(file.name);
$('#filename').show();
$('.cargando').show();
$('.uploaded').hide();
$('#file').hide();
name = file.name;
size = file.size;
type = file.type;
uploadAjax();
}
});
$('#uploadremove').click(function(e){
e.preventDefault();
$('.alert.alert-danger').hide();
$('#file').show();
$('.cargando').hide();
$('#filename').hide();
$('#uploadok').hide();
$('#uploadremove').hide();
$('#file_id').val("0");
$('.fileinput-button').show();
$('.savebtn').toggleClass('disabled');
$('.uploaded').hide();
});
}
function uploadAjax(){
var inputFileImage = document.getElementById("file");
var filelocation = $('#file').val();
var file = inputFileImage.files[0];
var info = new FormData();
var tipo_archivo = $("#file").attr('accept');
var tipo_archivo = type;
info.append('tipo', tipo_archivo); console.log(file);
var url = HTTP+"admin/uploadfile";
$.ajax({
url:url,
type:'POST',
contentType:false,
data: info,//{archivo : file, tipo : tipo_archivo},
processData:false,
cache:false,
success:function(response){
if(response != '' && !($.isNumeric(response)) ){
$('.alert.alert-danger #uploaderror').html(response);
$('.alert.alert-danger').fadeIn(2000);
$('.cargando').hide();
$('#filename').hide();
$('#file').show();
}
else{
$('.cargando').hide();
$('#uploadok').show();
$('#uploadremove').show();
$('#file_id').val(response);
$('.fileinput-button').hide();
$('.savebtn').toggleClass('disabled');
if(tipo_archivo == "image/*"){
console.log(file);
}
}
}
});
}
And this is the HTML form:
<form class="form-horizontal validate" role="form" method="post" action="<?=fk_link().'admin/savecv'?>">
<input name="location" type="hidden" class="location" value="admin/addcv/<?=#$profesor['id']?>" >
<input name="profesor_id" type="hidden" value="<?=#$profesor['id']?>" >
<div class="form_message">
<div class="alert alert-warning">
</div>
</div>
<?
$texto = "Seleccionar Archivo PDF";
if(#$profesor['profesor_cv']){ $texto = "Cambiar Cv";?>
<div class="uploaded">
<a class="btn btn-success fileDownloadPromise" target="_blank" href="<?=fk_link().'uploads/'.#$cv['cv']?>">
<i class="glyphicon glyphicon-cloud-download"></i>
<span>Descargar</span>
</a>
</div>
<?
} else $texto = "Seleccionar Archivo PDF";?>
<span class="btn btn-danger fileinput-button">
<i class="glyphicon glyphicon-cloud-upload"></i>
<span><?=$texto?></span>
<!-- The file input field used as target for the file upload widget -->
<input id="file" type="file" name="fileToUpload" id="filesToUpload">
</span>
<span class="cargando"><img src="<?=fk_theme_url().'/images/loading.gif'?>"></span>
<span id="filename"></span>
<input id="file_id" name="file_id" type="hidden" value="0" >
<span id="uploadok" class="glyphicon glyphicon-ok"></span>
Cambiar
<div class="clearfix" style="height:10px"></div>
<div class="alert alert-danger col-md-3" style="display:none;">
<span class="glyphicon glyphicon-warning-sign"></span>
<span id="uploaderror">error example</span>
</div>
<input class="btn btn-primary savebtn disabled" value="Guardar" type="submit">
</form>
As I said, everything worked fine but now it only works with images.
info.append('tipo', tipo_archivo);
Up there should be:
info.append('tipo', file);
This question already has answers here:
jQuery Ajax File Upload
(27 answers)
Closed 9 years ago.
I am using ajax form to display form dynamically in which it contains the file upload option. I'm getting the post values of every text values but the File array is empty.
I have executed print_r($_POST) and print_r($_FILES) to see the post data, the $_FILES Array is showing null value.
Here is the form I'm using.
<form class="form-3 form-horizontal ajxfrm" id="step-three" enctype="multipart/form-data" action="<?php echo $html->addLink(array('controller'=>'homes','action'=>'step_three_ajax')); ?>" method="post">
<div id="calendar">
<div class="clear"></div>
<div style="position:relative">
<div class="control-group">
<div class="control-label"><label class="control-label">Name</label></div>
<div class="controls"><input id="name" type="text" name="name" /></div>
</div>
</div>
<div style="position:relative">
<div class="control-group">
<div class="control-label">Email</div>
<div class="controls"><input id="email" type="text" name="email" /></div>
</div>
</div>
<div style="position:relative">
<div class="control-group">
<div class="control-label">Contact</div>
<div class="controls"><input id="contact" type="text" name="contact" /></div>
</div>
</div>
<div style="position:relative">
<div class="control-group">
<div class="control-label">Files<br/><span style="font-size:10px; font-style:italic">(Optional)</span></div>
<div class="controls">
<input id="fileupload" type="file" name="fileupload" /><br/>
</div>
</div>
</div>
<div style="position:relative">
<div class="control-group">
<div class="control-label">Your Message</div>
<div class="controls"><textarea id="message" rows="3" name="message"></textarea></div>
</div>
</div>
<div class="clear"></div>
</div>
<div id="submit">
<input type="hidden" name="post" value="1"/>
<input type="submit" class="btn green" value="Next"/>
</div>
</form>
Here is the ajax call
$('.ajxfrm').live('submit',function(){
var thisObj = this;
var submit = true;
if('step-two'==$(thisObj).attr('id')){
submit = stepTwo();
}else if('step-three'==$(thisObj).attr('id')){
submit = stepThree();
}
if(submit){
$.ajax({
type: "POST",
data: $(thisObj).serialize(),
url: $(thisObj).attr('action'),
beforeSend: function(){
showOverLayer();
},
success: function(data){
$(thisObj).parent("#content").empty().html(data).hide().fadeIn(function(){
setBlocks();
setLiClick();
hideOverLayer();
});
changeCalNaviHref();
}
});
}
return false;
});
Here im calling the upload function using $booker->uploadfiles(); in controller
here is the controller method function
public function step_three(){
//save booking
if(isset($_POST['post'])){
$booker = new Booker();
//create booker
$_SESSION['userdat']['name']=$_POST['name'];
$_SESSION['userdat']['email']=$_POST['email'];
$_SESSION['userdat']['contact']=$_POST['contact'];
$_SESSION['userdat']['message']=$_POST['message'];
if($booker->setsessions($_SESSION['userdat']))
{
$booker->uploadfiles();
$this->redirect(array('controller'=>'homes','action'=>'step_four'));
}
else
{
$this->setFlashMsg('Please Provide Valid Information','message-box ok');
}
}
}
here is the model function uploadfiles()
public function uploadfiles()
{
if(isset($_FILES['fileupload']))
{
$errors= array();
foreach($_FILES['fileupload']['tmp_name'] as $key => $tmp_name )
{
print_r($_FILES);
exit;
$file_name = $key.$_FILES['fileupload']['name'][$key];
$file_size =$_FILES['fileupload']['size'][$key];
$file_tmp =$_FILES['fileupload']['tmp_name'][$key];
$file_type=$_FILES['fileupload']['type'][$key];
if($file_size > 2097152)
{
$errors[]='File size must be less than 2 MB';
}
$upload_dir = ROOT;
$desired_dir="/uploads/";
if(empty($errors)==true)
{
if(is_dir($desired_dir)==false)
{
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false)
{
//$file_path=$upload_dir."$desired_dir/".$file_name;
move_uploaded_file($file_tmp,$upload_dir."$desired_dir/".$file_name);
}
else
{ // rename the file if another one exist
$file_path=$upload_dir."$desired_dir/".$file_name.time();
rename($file_tmp,$file_path) ;
}
}
else
{
print_r($errors);
}
}
if(empty($error))
{
//echo "Success"; exit;
return true;
}
return false;
}
What am I missing here?
Try this.
$('.ajxfrm').live('submit',function(){
var thisObj = $(this),
submit = true;
if('step-two'== thisObj.attr('id')){
submit = stepTwo();
}else if('step-three'== thisObj.attr('id')){
submit = stepThree();
}
if(submit){
$.ajax({
type: "POST",
data: thisObj.serialize(),
url: thisObj.attr('action'),
beforeSend: function(){
showOverLayer();
},
success: function(data){
thisObj.parent("#content").empty().html(data).hide().fadeIn(function(){
setBlocks();
setLiClick();
hideOverLayer();
});
changeCalNaviHref();
}
});
}
return false;
});
Can you show me one console.log(data) on the success method?
Thanks
You cannot send files using 'old' AJAX (not this way).
If you want to send files, take a look at XMLHttpRequest2. Pretty good tutorial is here - http://www.html5rocks.com/en/tutorials/file/xhr2/
Two total long shots here:
1) You mentioned that your sessioning code is "up top". Are you using something like session_regenerate_id there? That will mess with parallel uploads.
or
2) Take a look at whether your session file is locked when other sessions are coming in. google an article or two on session_write_close().
But its more likely to be #1.