jQuery uploadify change file name as it is being uploaded.

坚强是说给别人听的谎言 提交于 2019-12-25 05:14:41

问题


I am using uploadify (a jQuery plugin) to upload files as I am adding clients to my DB.

I would like to attach files to clients. The issue #1 is that the client is a new client so it has not been added to the DB just yet. I have overcome this by getting the next Client_ID in the DB.

NOW the real issue is that all files that are uploaded should be prepended with this ID...something like: (29) ---i would like the parenthesis as an added open and close of the client_ID----I have searched on stackoverflow and uploadify.com but can't make heads or tails on how to do this.

I NEED TO DO IT VIA JS, because of the fact that I am using the PHP elsewhere in my application and I don't want to change it, if at all possible.

SOME CODE: here is the jQuery thus far

$('#file_upload').uploadify({
    'uploader'  : 'uploader/uploadify.swf',
    'script'    : 'uploader/uploadify.php',
    'cancelImg' : 'uploader/cancel.png',
    'folder'    : 'clientFiles',
    'buttonText'  : 'Attachments',
    'removeCompleted' : false,
    'multi'          : true,
    'auto'      : true
  });

PHP that gets next Client_ID

$sql = "SELECT Client_ID FROM clients";
    $result = $db->sql_query($sql);
    $nextClientID= mysql_num_rows($result)+1;

THANKS for ANY HELP!!!


回答1:


you just need to return $targetPath from your uploadify.php file, like this --

echo $targetPath

And please remove echo '1'

And now you have to get the renamed file name. You can get this in onUploadSuccess function. onUploadSuccess() takes three parameters (file, data, response),

where file gives you the actual name of file you browsed through your computer, and data gives you the renamed file name which you generated through your uploadify.php code as per your requirement.

So you can try the below code --

'onUploadSuccess' : function(file, data, response) {
        alert('Renamed file name is - ' + data);
    }

I hope this will help out. One of my friend told me this, and I got my work done then :)




回答2:


add to JS

onComplete: function(file, tmpname){
 alert(tmpname);
}

Add to

uploadify.php

die( $temp_name );


来源:https://stackoverflow.com/questions/7707687/jquery-uploadify-change-file-name-as-it-is-being-uploaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!