<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader' : 'scripts/uploadify.swf',
'script' : 'scripts/uploadify.php',
'buttonImg' : 'css/btn_browseFiles.png',
'rollover' : 'true',
'wmode' : 'transparent',
'height' : '26px',
'width' : '109px',
'cancelImg' : 'cancel.png',
'folder' : 'uploads',
'queueID' : 'fileQueue',
'simUploadLimit' : '2',
'auto' : true,
'multi' : true,
'onComplete' : function(event, queueID, fileObj, response, data) {
$('#filesUploaded').append('<li><strong>file:</strong> '+fileName+'</li>');
}
});
});
</script>
I want to get the "+fileName+" to echo in PHP so I can pass it in a contact form.
<?php $que = ""; ?>` fill in the blanks
<input type="hidden" name="" value="<?php echo($que); ?>">
Besides doing the following, I don't know of a way to pass Javascript variables to PHP...
<script type="text/javascript>
location.href="thisPage.php?fileName=" + fileName;
</script>
And then you would use PHP to do:
<?PHP $que = $_GET["fileName"]; ?>
If you want to use the text in the filename variable, you will need to pass it to a server request somehow.
It can be done several ways:
cookie
getline variable/query string
post variable (put it in a form element)
If you just want to get it into a value on the current page, you should be able to use javascript to do it:
#('#id_of_element').val(filename);
This is assuming you are using jQuery.
This looks like some sort of uploading flash component. If it is uploading the file to your server, then you should be able to intercept the request and work with it from there.
$trigger('uploadifyComplete',ID,{
'name' : event.currentTarget.name,
'filePath' : getFolderPath() + '/' + event.currentTarget.name,
'size' : event.currentTarget.size,
'creationDate' : event.currentTarget.creationDate,
'modificationDate' : event.currentTarget.modificationDate,
'type' : event.currentTarget.type
},
can you see these?so you can use fileObj.name to get file name.
Related
this is my code:
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : '../js/uploadify/uploadify.swf',
'uploader' : '../js/uploadify/uploadify.php',
'height' : '60',
'width' : '60',
'folder' : '../uploads/',
'muti' : true,
'displayData': 'speed',
'scriptData' : {'evento' : '<?php echo $galery['event'] ?>'},
});
});
I try to pass a value of a variable to the file uploadify.php where there will register these data in the database, but can not in any way ... I've tried looking at some papers but the result is the same ...
You can tray to create session_id() and pass to this value through by uploadify. Then call the session id from acton page. And match them.
I'm building a site (in php) that uses uploadify to allow a user to upload portfolio images.
I have uploadify working fine, but I'm just wondering the best way of showing the uploaded images on the page once they have been uploaded. Is it possible to do without a page refresh?
I've pasted my uploadify code below:
<script>
<?php $timestamp = time();?>
var counter = 1;
$(function() {
$('#file_upload').uploadifive({
onUploadComplete: function(event, queueID, fileObj, reponse, data) {
//alert(counter);
counter = counter +1 ;
},
'buttonText' : 'Upload Images...',
'uploadLimit' : 12,
'uploadScript' : '/includes/uploadifive.php',
'checkScript' : '/includes/check-exists.php',
'auto' : true,
'method' : 'post',
formData : {
'page_id' : '<? echo $pageDetails->row['page_id'] ?>',
'counter' : counter,
'timestamp' : '<? echo $timestamp;?>',
'token' : '<? echo md5('unique_salt' . $timestamp);?>'
},
});
});
</script>
I'm not too sure how to get the file name from uploadify
Sure, you can just add img elements to the page dynamically via the DOM:
var img = document.createElement('img');
img.src = "/path/to/the/new/img.png";
document.getElementById("somecontainer").appendChild(img);
Live Example | Source
You may need to do an ajax call to the server to get the path of the new image, unless that falls out naturally from your application logic.
In the edition I use there is a function
onUploadSuccess : function(file,data,response){
}
Then I can get file name by file.name;
So in your code maybe the fileObj, You can try fileObj.name to get the name of the file you upload.
I have a jQuery fancybox that takes the content from an iframe, here's the link to popup the box:
<a class="action_btn recommend_btn" act="recommend" href="recommend.php">Recommend</a>
and here's the code for the fancybox:
$(".action_btn").not(".save").click(function() {
$.fancybox({
'width' : 560,
'height' : 530,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'href' : $(this).attr('href')
});
return false;
});
now I would like to post something to this recommend.php, so I can use this attribute/value in recommend.php, how can I do this?
One way I can think of is to store a session in the page prior to hyperlinking, but doesn't seem right.. seems like there should be a better way to do this
You should still be able to use the _GET http variable I think so:
Click
Then in recommend.php use $_GET['some_variable']. Unless fancybox does something crazy with iFrames.
since you already are using jQuery and possibly want to do this on the fly use .post().
$(".action_btn").not(".save").click(function() {
$.fancybox({
'width' : 560,
'height' : 530,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'href' : $(this).attr('href')
});
// example uses a json object to pass data, change here to what you need.
// will also accept jQuery objects like so:
// $.post('recommend.php', $('#myData').serialize());
$.post('recommend.php', { name: 'John', time: '2pm' } );
return false;
});
i am trying to use uploadify, to upload pdf or txt files, but without success. Uploadify 2.1.4 uploads just image files. I tried to just rename file extensions, tried to allow ., tried to namely allow pdf or other formats, but Uploadify uploads just F******g images and i do not know why...
Please help me.
I use these settings:
public function show()
{
if(!$this->dir) throw new exception("Upload dir is not set");
if(!$this->url) throw new exception("Upload url is not set");
$rem=(isset($_POST[$this->name."-rem"]))?$_POST[$this->name."-rem"]:"";
$tpl='<div id="'.$this->name.'-queue" class="upload-queue">'.$this->fillQueue().'</div>';
$tpl.='<input id="'.$this->name.'-uploadify" name="'.$this->name.'-uploadify" type="file" />';
$tpl.='<input id="'.$this->name.'-files" name="'.$this->name.'-files" type="hidden" />';
$tpl.='<input id="'.$this->name.'-rem" name="'.$this->name.'-rem" type="hidden" value="'.$rem.'"/>';
//$tpl.='<link rel="stylesheet" type="text/css" href="/uploadify/uploadify.css" />';
$tpl.="<script type=\"text/javascript\"><!--
var ".$this->name."Files=".$this->currentCount.";
function ".$this->name."DeleteFile(where)
{
var rem=$('#".$this->name."-rem').val();
if(rem!='') rem+=',';
$('#".$this->name."-rem').val(rem+$(where).parent().attr('id'));
$(where).parent().remove();
".$this->name."Files--;
if(".$this->name."Files<".$this->count.") $(\"#".$this->name."-uploadifyUploader\").show();
}
$(document).ready(function() {
$(\"#".$this->name."-uploadify\").uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '".$this->url."',
'scriptData' : {'".session_name()."':'".session_id()."'},
'cancelImg' : '/uploadify/cancel.png',
'folder' : '".$this->dir."/thumb',
'queueID' : '".$this->name."-queue',
'auto' : true,
'multi' : ".(($this->count>1)?"true":"false").",
'buttonText' : '".$this->buttonName."',
'fileExt' : '".rtrim($this->fileExt,";")."',
'fileDesc' : '".rtrim($this->fileDesc,",")."',
onError : function (a, b, c, d) {
if (d.status == 404)
alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
else if (d.type === \"HTTP\")
alert('error '+d.type+\": \"+d.status);
else if (d.type ===\"File Size\")
alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
else
alert('error '+d.type+\": \"+d.text);
},
onComplete : function(event, queueID, fileObj, response, data){
$(\"#".$this->name."-queue\").append('<div id=\"'+fileObj.filePath+'\" class=\"item\"><div style=\"background: url('+fileObj.filePath+') no-repeat 50% 50%\"></div><img src=\"/uploadify/cancel.png\" class=\"delete-file\" onclick=\"".$this->name."DeleteFile(this);\"></div>');
$('#".$this->name."-queue').sortable('refresh');
".$this->name."Files++;
if(".$this->name."Files>=".$this->count.") $(\"#".$this->name."-uploadifyUploader\").hide();
},
onInit : function(){setTimeout(function(){if(".$this->name."Files>=".$this->count.") $(\"#".$this->name."-uploadifyUploader\").hide();},500);}
});
$('#".$this->name."-queue').sortable();
$('#".$this->name."-queue').disableSelection();
$('form').submit(function(){
$('#".$this->name."-files').val($('#".$this->name."-queue').sortable('toArray'));
});
});
--></script>";
return array("",$tpl);
}
...
Thank you!
var settingObject = {
'uploader' : '/uploadify/uploadify.swf', // set your path
'checkScript':'/uploadify/check.php', // set your path
'script' : '/uploadify/uploadify.php', // set your path
'cancelImg' : '/uploadify/cancel.png', // set your path
'folder' : '/files/useruploads',
'auto' : true,
'fileExt' : '*.jpg;*.gif;*.png;*.txt;*.pdf;*.doc;*.docx', // any extension you want to allow
'fileDesc' : 'Upload Files (.JPG, .GIF, .PNG, .TXT, .PDF, .DOC, .DOCX)',
'removeCompleted': false
};
$("#file-1").uploadify(settingObject);
Reference : (File-Extension) http://www.uploadify.com/documentation/options/fileext/
This should work for you..
There might be an issue of Size Limit for each file. Try adding the following
'sizeLimit': 500000
Try to edit upload_max_filesize in your php.ini
Change your current options to these:
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads',
'fileTypeExt' : '*.jpg;*.gif;*.png', <== this line
'fileTypeDesc' : 'Image Files'
});
For reference: http://www.uploadify.com/documentation/uploadify/filetypeexts/
Change these lines:
'fileTypeExt' : '*.txt;*.pdf;',
'fileTypeDesc' : '*.txt and *.pdf',
Use 'fileExt' : '*.pdf;*.jpg;*.jpeg;*.png', instead of the filename that reads it.
that is my first post
I am trying here, to get the names of the files that are uploaded, so that the user can delete it if desired, the same way as yahoo.
$("#uploadifysub1").uploadify({
'uploader' : 'JS/uploadify.swf',
'script' : 'JS/uploadify.php',
'cancelImg' : 'cancel.png',
'buttonImg' : 'attach.png',
'folder' : 'uploads',
'queueID' : 'divquickuploadProgress1',
'auto' : true,
'multi' : true
});
the problem is that I cannot get files names, any suggestions?
is there any function in uploadify, that can remove an uploaded file, or I have to do that myself??
Thanks in advance.
thanks to "Codler", I could solve this problem, I will share the code, maybe it will help.
$("#uploadifysub1").uploadify({
'uploader' : 'JS/uploadify.swf',
'script' : 'JS/uploadify.php',
'cancelImg' : 'cancel.png',
'buttonImg' : 'attach.png',
'folder' : 'uploads',
'queueID' : 'divquickuploadProgress1',
'auto' : true,
'multi' : true,
'onComplete' : function(event, queueID, fileObj, reposnse, data) {
// write your own implementation
}
});
my implementation was like that
var cod = '<tr>';
cod += '<td align="left">'+fileObj.name+'</td>';
cod += '<td align="left">';
cod += '<span onclick="removeprev(this,'+fileObj.name+')" style="cursor: pointer;"> ';
cod += '[remove]</span>';
cod += '</td>';
cod += '</tr>';
$('#uploaded_files').append(cod);
Thanks again
Quote from uploadify
fileDataName
The name of your files array in the
upload server script. Default =
‘Filedata’
PHP code
$_FILES['Filedata']['tmp_name'];
why didn't you just set the removeCompleted option to false. It queues all the uploaded files.