开发者

jQuery uploadify change file name as it is being uploaded.

开发者 https://www.devze.com 2023-04-11 16:24 出处:网络
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 ad

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开发者_C百科 = "SELECT Client_ID FROM clients";
    $result = $db->sql_query($sql);
    $nextClientID= mysql_num_rows($result)+1;

THANKS for ANY HELP!!!


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 :)


add to JS

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

Add to

uploadify.php

die( $temp_name );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号