Has anyone used this plugin? I don't know if my setup is right, but I think so.
$(document).ready(function () {
$("#uploadify").uploadify({
'uploader': '/extra/flash/uploadify.swf',
'script': '/admin/uploads/artistsphotos',
'checkScript': '/admin/uploads/artistsphotos',
'cancelImg': '/images/cancel.png',
'folder': '/img/artists',
'queueID': 'fileQueue',
'auto': false,
'multi': true,
'onComplete': function (a, b, c, d, e) {
alert(d);
},
'onAllComplete': function (event, data) {
//something here
//alert(data);
}
});
$('.vla').click(function () {
$("#uploadify").uploadifyUpload();
return false;
});
});
If I check with firebug I receive this: http://screencast.com/t/z9PY53bi, but I can't work with the files in PHP,and I also have enctype=".. on the <form>, but when I check the $_FILES array is empty, is my plugin setup wrong?
I have used uploadify before.
Are you using the most recent version of uploadify?
also you shouldn't need a form tag, the 'script' variable is where the uploader sends the file data. Any other information that needs to be sent with it has to be placed in the 'scriptData' variable. Also, I'm not sure if you can send both the script and the checkScript to the same file that might be what is causing the problem.
The script is the file that processes the upload, the checkScript is a script that ensures that the file is not already on the server.
Related
I just try with Apache Cordova and normal jQuery to make an Ajax-Request.
I have this code so far:
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
$(function () {
var datastring = "test";
$.ajax({
type: "POST",
url: "serverfiles/app-db-connection.php",
data: dataString,
success: function (data) {
$('#result').html(data);
alert("test");
}
});
$('#result').html("test");
});
};
the .php file is local and works, if I call it through the browser. Also the ajax-Part works fine in other normal webprojects.
So, what should I care about, then useing cordova. There have to be some issues with cordova.
Even the test-alert isn't working.
A little hints how normal Ajax-requests work with cordova would help me a lot.
Normal Jquery-Code is working fine on the test-machines.
Ok. just solve the problem.
2 mistakes done:
first: Var datastring and "dataString" were not written equal.
second: it is not allowed to use in url-property a relative file-path. This because the file will not compiled by the app it self... it has to be an absolute path: http://blabla.com ... not ir works fine.
I'm using a great plugin - dropzone.js (dropzonejs.com) to make my site a little more fancy when registering a new user.
Basically, the user fills out a form, drops a couple images into the "dropzone", and clicks "Submit", which fires an ajax call that posts the form to a php script.
I have dropzone parameters set to enqueForUpload:false, which keeps the files from auto-uploading, since I need them to upload into uploads/$userid, after the new user id has been created. I can give dropzone header params, which I'm assuming post to the url, similar to an ajax call, instead of data: {'userid': userid}, dropzone uses headers: {'userid': userid}... However, dropzone gets initialized on document.ready, and as the userid variable isn't declared yet, dropzone fails to initialize.
I'm guessing I'm going to need to initialize dropzone with document.ready, but not give it headers just yet. Then after the ajax form processing is successful and returns userid, call dropzone to upload and give it the headers at that point. Problem is, I don't know what code would need to be called to make that happen.
Initialize Dropzone on ready:
$(document).ready(function(){
$('#dropzone').dropzone({
url: 'dropzoneprocess.php',
maxFilesize: 1,
paramName: 'photos',
addRemoveLinks: true,
enqueueForUpload: false,
});
});
Then...
$('#submit').on('click', function(){
validation crap here
$.ajax({
type: 'post',
url: 'postform.php',
data: {'various': form, 'values': here}
datatype: 'json',
success: function(data){
var userid = data.userid;
/* (and this is what I can't figure out:)
tell dropzone to upload, and make it
post userid to 'dropzone.php' */
});
});
If you use the latest Dropzone version, the parameter enqueueForUpload has been removed, in favour of autoProcessQueue which makes the whole queuing easier.
So, just call myDropzone.processQueue() as soon as you want all files to be uploaded.
To add additional parameters to the XHR you can simply register to the sending event, which gets the xhr object as second and formData as third parameter, and add the data yourself. Something like this:
myDropzone.on("sending", function(file, xhr, formData) {
// add headers with xhr.setRequestHeader() or
// form data with formData.append(name, value);
});
I used enyo answer, but i used many dropzones with data-id attribute in my page so I used:
$('div.dropzone').dropzone({
url: 'img.php'
});
var sendingHandler = function(file, xhr, formData) {
formData.append('id', $(this.element).data('id'));
};
$('div.dropzone').each(function() {
Dropzone.forElement(this).on('sending', sendingHandler);
});
This is my code
<script>
$(document).ready(function() {
// delete the entry once we have confirmed that it should be deleted
$('.delete').click(function() {
var parent = $(this).closest('tr');
$.ajax({
type: 'POST',
url: 'delete.php',
data: 'ajax=1&delete=' + $(this).attr('id'),
success: function() {
parent.fadeOut(300,function() {
parent.remove();
});
}
});
});
$('.delete').confirm({
});
});
</script>
My question is why delete.php is not executing? It's in the same folder, do I need type absolure url to this file? But the best of it is that row in table is deleting, but php file is not executing.
And second question is why this code is not working without this line:
$('.delete').confirm({
});
In php file i got this to know is it executed:
<script>
alert('aaaa');
</script>
Or even I had change it on echo 'something'; but still not working
If the row is deleted the certainly the php file is executed and you have to check the url data as #Saifuddin has described.
use firebug console to see your result. and also you are not passing parameter to the success function
so change this
data: { ajax: 1, delete: $(this).attr('id')},
and also this
success: function(msg) {
alert(msg)
parent.fadeOut(300,function() {
parent.remove();
});
}
I assume that the php file is executed in your case, while better approach to define the url with absolute path like http://www.example.com/delete.php. however the way you pass data is not as per standard.
so replace this line.
data: 'ajax=1&delete=' + $(this).attr('id'),
with
data: { ajax: 1, delete: $(this).attr('id')},
and for debugging print $_POST variable in your php file.
hope it helps.
I would add an error handler to see what is happening with the ajax call, something like this:
error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
Keep in mind that the ajax call gets the current directory preppended to the relative uri you set. I assume you are sending the request to a working web server, i.e. using the HTTP protocol.
There is no confirm() jQuery function as far as I know. You usually do:
if (confirm('Are you sure you want to delete this item?')) do_delete();
The confirm() method returns true when the user selects OK, and false otherwise.
Cheers.
I'm trying to get Uploadify 2.1.4 to work with Codeigniter 2.1.0 and CSRF and I'm not having much luck. I have a very basic upload controller & the following code for uploadify:
$(function() {
var cct = $.cookie('csrf_cookie_name');
$('#uploadifyMe').uploadify({
'uploader' : '<?php echo site_url(); ?>js/uploadify/uploadify.swf',
'script' : '<?php echo site_url(); ?>upload/',
'cancelImg' : '<?php echo site_url(); ?>js/uploadify/cancel.png',
'multi' : true,
'auto' : false,
'fileExt' : '*.jpg;*.jpeg',
'fileDesc' : 'Image Files (JPG, JPEG)',
'fileDataName' : 'imgData',
'queueID' : 'fileQueue',
'simUploadLimit' : 1,
'sizeLimit' : 7340032,
'removeCompleted': false,
'scriptData' : { 'csrf_token_name' : cct, 'upload' : 'true' },
'onSelectOnce' : function(event, data) {
$('.uploadifyProgress').addClass('progress');
$('.uploadifyProgressBar').addClass('bar');
},
'onComplete' : function(e, i, f, r, d) {
console.log(r);
},
'onError' : function(e, i, f, eO) {
console.log(eO);
if(eO.info == 500) {
$('#status').prop('class', 'alert alert-error').html('<a class="close" data-dismiss="alert">×</a><h4>Hmmm. Something gone wrong it has.</h4> Yoda has discovered that your security token has expired. This is because you have been here for longer than two hours. we cannot refresh your key automatically, please refresh the page and try again.');
}
}
});
});
The problem is when I upload an image I get a HTTP 500 thrown back at me. I now know it's due to CSRF being turned on since if I turn it off it works fine.
I've tried a load of solutions to the problem. The one you can see in my code, and a one from here that clones your session data and sends it across with the CSRF key, but nothing works. I always end up with a 500 HTTP unless I turn off CSRF.
If anyone can help it would be really appreciated. I realize this question seems to get asked a lot, and it's driving me nutty. On a side note passing the CSRF along with standard AJAX requests works fine, just not with uploadify.
Use this code, it enables you to define an array of controller methods that are not subject to CSRF: https://github.com/EllisLab/CodeIgniter/pull/236.
The issue is that Uploadify uses a Flash object, which is like a completely different browser, with different session, so the CSRF won't match your session if you POST the cookie data.
You would need to override the original CSRF function with a MY_Security.php file and make so you can get around it by, in example, sending your entire session cookie via POST and make so the CSRF can read it, so you can be matched.
You might as well try HTML5 uploaders like https://github.com/blueimp/jQuery-File-Upload that at least gives you a better chance at not having to do such overrides.
I was wondering if it's possible to store form data such as 'title' and 'description' in a javascript session?
I'm using the uploadify script to have a flash uploader, but the script isn't passing the title and description. This is my code at the moment;
<script type="text/javascript">
jQuery(document).ready(function() {
title = $("input#title").val();
description = $("textarea#description").val();
$('#uploadImage').uploadify({
'uploader': 'flash/uploadify.swf',
'script': 'process/process_uploaded_image.php',
'folder': 'submitted/pictures',
'cancelImg': 'images/cancel.png',
'queueID' : 'fileQueueImages',
'auto' : false,
'multi' : false,
'fileExt' : '*.jpg;*.png;*.gif;*.jpeg;*.JPG',
'fileDesc': 'Images ONLY (.jpg, .png, .gif, .jpeg, .JPG)',
'buttonText' : 'BROWSE',
'scriptData': {'title':title,'description':description,'user':'<?php echo $usr["id"] ?>'},
'sizeLimit' : '2097152', //2MB
//'buttonImg' : '/components/com_mm/assets/images/button-upload-images.png',
//'width' : '218',
//'height' : '66',
onAllComplete: function() {
//$('#uploadedImage').load(location.href+" #uploadedImages>*","");
//location.reload(); //uncomment this line if youw ant to refresh the whole page instead of just the #allfiles div
location.href = "upload-pics-thanks.php";
},
//onComplete: function(a, b, c, d, e){
// if (d !== '1')
// alert(d);
//},
onError: function (a, b, c, d) {
alert("Error: "+d.type+" Info: "+d.info);
},
onSelect: function () {
}
});
});
</script>
Check out this SO answer and in case that doesn't work...
Did you see this post in the Uploadify forums? Maybe it'll point you in the right direction, and wow so much spam in those forums.
http://www.uploadify.com/forum/viewtopic.php?f=7&t=3120
JavaScript does not have sessions. Probably the best way is to send your title&description via AJAX to the server.
If you use latest version of uploadify, the data in scriptData will be passed to script as either _POST or _GET (default is now POST) variable. So in your php file, you can get the title and description using:
$_POST['title']
$_POST['description']
$_POST['user']
Just consider it same with handling form submit, only it's originated from uploadify flash. Also note, the flash is not passing the current cookies that currently exist in the browser. If your php is using session stored in the cookies, it must be tweaked to read it from $_POST instead.
I use CodeIgniter, and there are patch for that in CodeIgniter forum. If you just use build in PHP session, you can pass the PHPSESSID inside scriptData, then in side script PHP, reinitialize session using passed data. It's have been answered in other question in stackoverflow, just search it with uploadify keyword.