fineUploader deleting a file - php

I use Fine Uploader Version: 5.0.8
1) I choose file 1.png
2) PHP script renames and upload with a new name fdba4551.png
3) I want to delete the file but not know how to pass parameters unlink($UploadDir.$_POST['??????????']);
I can not delete the file fdba4551.png
my PHP
if($method == 'POST')
{
if(move_uploaded_file($TempName, $PatchNewFile))//$PatchNewFile = uploads/fdba4551.png
{
$return = array('success'=>true,'uuid'=>$uuid,'uploadName'=>$NewFile);//$NewFile = fdba4551.png
echo json_encode($return);
}
}
elseif($method == 'DELETE')
{
unlink($UploadDir.$_POST['??????????']);//?????????????
}
my java script
<script type="text/javascript">
$(document).ready(function()
{
$('#upl').fineUploader({
debug:true,
deleteFile:{
enabled:true,method:'POST',endpoint:'upload/'
},
request:{
endpoint:'upload/'
},
callbacks:{
onComplete:function(id, name, response)
{
$('#file').append('<input type="hidden" name="load_file[]" value="'+response.uploadName+'" id="'+id+'">');
},
onDelete:function(id)
{
$('#file #'+id).remove();
}
},
validation:{allowedExtensions:['jpeg','jpg','png','gif'],acceptFiles:'image/jpeg,image/png,image/gif',itemLimit:10,sizeLimit:5*1024*1024}
});
});
</script>

As described in the delete file endpoint handler section of the docs:
Handle the POST or DELETE at your specified endpoint
Locate the file based on the file UUID included in the path of the request.
Delete the file.

Related

Copy a multiple file from client system to server

I don't have any idea to copy a file from client system to server.
Short Description
I am using upload folder dialog box to upload a multiple file from particular path.
XML file is mandatory, because i need to extract some information to process
While upload event i read all the information i need to process
$("#myInput").change(function() {
var names = [];
var formData = new FormData();
for (var i = 0; i < $(this).get(0).files.length; ++i)
{
var F_name= $(this).get(0).files[i].name;
var extension = F_name.replace(/^.*\./, '');
if(extension != "xml" && extension != "db"){
formData.append('userfiles[]', $(this).get(0).files[i], F_name);
}
else if(extension == "xml"){
//Gathering info
}} });
User interface fields are filled automatically after this process and user have to fill some more fields. While user click process button in server side i create folder and some new XML files too. Everything is fine except , copy a file from client to server.
//Jquery
$("#process_but" ).click(function() {
$.ajax({
type: "POST",
url: "Asset/PHP/function.php",
data: {action: "action1", DOI:doi, TLA:tla, STITLE:S_Title, SHEAD:S_Head, SLINK:S_Link, LTYPE:link_type, DESC:description, ATITLE:Art_title, JTitle:JOU_title, ANAME:Author_name, FSHARE:Fig_share, FNAMES:filenames, FCOUNT:filecount},
success: function(response) {
if(response == 1)
{alert("success");}
else
{alert("Something goes wrong.....");}
},
error: function() {
alert("Error");
}
});
});
//php
<?php
session_start();
$action = $_POST['action'];
if($action == "action1")
{
//what i have to do
}
?>

Start downloading zip automatically which was made by Ajax

I have a button which let server make zip file by Ajax.
$('.zipButton').click(function(){
console.log($(this).context.firstChild.data);
$(this).context.firstChild.data = "working......";
$(this).addClass('disabled');
var self = $(this);
$.post('{{path('acme_member_zip')}}',// make zip file on server.
function(response){
if(response.code == 100 && response.success){
console.log(response.message);
self.context.firstChild.data = "finish make zip";
alert("please download http://www.myserver.com/myzip/arc.zip");
}
else {console.log("no correct return");}
}, "json");
});
For now, after making zip I let user know where the zip file by alert.
However,I want to push on browser start downloading automatically.
How can I make it???
You can redirect the client to the ZIP url with document.location, like this :
$.post('{{path('acme_member_zip')}}',// make zip file on server.
function(response){
if(response.code == 100 && response.success){
console.log(response.message);
self.context.firstChild.data = "finish make zip";
document.location = "http://www.myserver.com/myzip/arc.zip";
}
else {
console.log("no correct return");
}
},
"json"
);
There are few way to achieve this.
1)
you can use the download attribute in the hyperlink
Your file Name
document.getElementById('download').click();
2)
Use the jQuery file Download plugin
https://github.com/johnculviner/jquery.fileDownload
3)
Set window.location = 'your file path'; after the success

Drag and Drop Jquery upload to PHP

I have seen many topics about this problem but none of them got a legit answer or a including PHP file.
I want to make a drag & drop saving tool. The problem is that my files are not getting uploaded to my ftp folder.
I got the following code:
HTML:
<div id="drop_zone">
<p>Drop Here</p>
</div>
<form enctype="multipart/form-data" id="yourregularuploadformId">
<input type="file" name="files[]" multiple="multiple">
</form>
JS:
$(function() {
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
etc.... dropping part
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
files = evt.dataTransfer.files;
uploadFile(files);
etc... getting file to my method
function uploadFile(droppedFiles){
// add your files to the regular upload form
var uploadFormData = new FormData($("#yourregularuploadformId")[0]);
if(droppedFiles.length > 0) { // checks if any files were dropped
for(f = 0; f < droppedFiles.length; f++) { // for-loop for each file dropped
uploadFormData.append("files[]",droppedFiles[f]); // adding every file to the form so you could upload multiple files
}
}
// the final ajax call
alert(uploadFormData);
$.ajax({
url : "php/uploadFile.php", // use your target
type : "POST",
data : uploadFormData,
cache : false,
contentType : false,
processData : false,
success : function(ret) {
alert(ret);
}
});
}
Got the above code from another topic. (alert(uploadFormData); -> gives me a Formdata aboject)
PHP:
move_uploaded_file($_FILES["file"]["tmp_name"],
"ftp/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
Can't make it work :<
The message i get from the callback function in my JS is:
Undefined index: file
Your PHP code needs to iterate over all of the files in the request. Based on your javascript, your PHP code should look something like this:
foreach ($_FILES["files"] as $file) {
move_uploaded_file($file['tmp_name'], $target);
}
The $target variable must point at the local destination for your file. See the PHP manual for more details.

how to pass php controller file to view php file in jquery function codeigniter

Hi Am new to PHP: i had tried to upload a image file with random generated nos .then i want to return the uploaded file name in view php and set in jquery function.here is code uploaded file.
// controller file this file only when i click upload calling
// controller file
function uploadfileview(){
$targeturl = getcwd()."/uploads/";
if($_SERVER['REQUEST_METHOD'] == "POST"){
$checkexisting = getcwd()."/uploads/".$_FILES['userfile']['name'][0];
$random_number = rand(0,1000000);
//checking the file is existing or not
if(file_exists($checkexisting)) {
if(move_uploaded_file($_FILES['userfile']['tmp_name'][0], $targeturl.$random_number.'-'.$_FILES['userfile']['name'][0])){
echo json_encode(array(
'files' => $random_number.'-'.$_FILES['userfile']['name'][0],
'post' => $_POST,
'fileurl' => getcwd()."/uploads/".$random_number.'-'.$_FILES['userfile']['name'][0]
));
$bb = $random_number.'-'.$_FILES['userfile']['name'][0];
}
}else{
if(move_uploaded_file($_FILES['userfile']['tmp_name'][0], $targeturl.$random_number.'-'.$_FILES['userfile']['name'][0])){
echo json_encode(array(
'files' => $random_number.'-'.$_FILES['userfile']['name'][0],
'post' => $_POST,
'fileurl' => getcwd()."/uploads/".$random_number.'-'.$_FILES['userfile']['name'][0]
));
}
$data['testing'] = $random_number.'-'.$_FILES['userfile']['name'][0];
return $this->$data('reimbursement');
}
// exit;
}
}
Here is the ajax upload form.function.
// for uploaded the file name
jQuery(function(){
var button = $('#uploader-button'), interval;
new AjaxUpload( button, {
action: baseUrl + "expensereimbursement/uploadfileview",
name: 'userfile[]',
multiple: true,
onSubmit : function(file , ext){
// Allow only images. You should add security check on the server-side.
if (ext && /^(jpg|png|jpeg|pdf)$/.test(ext)){
} else {
// extension is not allowed
$('#bq-reimbursement-form .error-ajax').text('Error: Invalid File Format').css('color','red').show().fadeOut(5000);
// cancel upload
return false;
}
// change button text, when user selects file
button.text('Uploading');
// If you want to allow uploading only 1 file at time,
// you can disable upload button
this.disable();
// Uploding -> Uploading. -> Uploading...
interval = window.setInterval(function(){
var text = button.text();
if (text.length < 13){
button.text(text + '.');
} else {
button.text('Uploading');
}
}, 200);
},
onComplete: function(file, response){
button.text('Upload');
window.clearInterval(interval);
// enable upload button
this.enable();
var obj = $.parseJSON(response);
if(obj.error){
$('#bq-reimbursement-form .error-ajax').text('Error: File Already Exist!').css('color','red').show().fadeOut(5000);
}else {
var url = "https://docs.google.com/viewer?url=" + obj.fileurl;
var html = '<li><input type="text" name="imageName[]" value="'+file +'" class="display-type" ><a class="filenames" target="_blank" href="'+url+'">'+file +'</a><span class="close-button display-type">x</span></li>';
$('#upload-file-bq .files').append(html);
}
}
});
});
var html = '<li><input type="text" name="imageName[]" value="'+file +'" class="display-type" ><a class="filenames" target="_blank" href="'+url+'">'+file +'</a><span class="close-button display-type">x</span></li>';
// file = my uploaded file name to be return from controller.
Here file only i want to return the uploaded file name can any one help me please.is this possible get the value in jquery.
CodeIgniter comes with a class for uploading files. You should use it. From looking at the CodeIgniter documentation for the Upload Class. You can do this after you've uploaded your file.
$aUploadData = $this->upload->data()
$aUploadData will then contain an array of data about the file you uploaded. To return the name of the file you uploaded you would do something like this
$aUploadData = $this->upload->data()
return $aUploadData['file_name']

Upload Image using ajaxupload

I am using Ajax Upload for file upload via ajax and php.
At js file i wrote following line of code:
$(document).ready(function() {
if ($('#uploadExists').length) {
var btnUpload = $('#uploadExists');
var u = new AjaxUpload(btnUpload, {
action: '/upload',
name: 'fname',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
//Bad file
return false;
}
},
onComplete: function(file, response){
if (! (/(\.jpg|\.png|\.jpeg|\.gif)/.test(response))) {
//Bad file
console.log(response);
return false;
} else {
console.log(response);
}
}
});
}
});
At /upload url what should I do?
I am writing things in PHP.
At /upload (for instance /upload/index.php) you receive the file via the $_POST variable. Try doing var_dump($_POST) to see what the filename is. Then you can use http://php.net/manual/en/function.move-uploaded-file.php to move the file as you would like. This script will be sent 1 file at a time from the multi-file upload, so you handle the upload as if you were handling a single upload via a standard html form.

Categories