jQuery uploadify更改文件名,因为它正在上载. [英] jQuery uploadify change file name as it is being uploaded.

查看:174
本文介绍了jQuery uploadify更改文件名,因为它正在上载.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将客户端添加到数据库时,我正在使用uploadify(一个jQuery插件)上传文件.

我想将文件附加到客户端.问题#1是该客户端是一个新客户端,因此尚未将其添加到数据库中.我已经通过在数据库中获取下一个Client_ID来克服了这一问题.

现在真正的问题是,所有上传的文件都应使用此ID开头...类似: (29)--- i希望将圆括号作为client_ID的附加打开和关闭----我已经在stackoverflow和uploadify.com上进行了搜索,但无法做到这一点>

我需要通过JS进行操作,因为事实是我在应用程序的其他地方使用了PHP,并且即使有可能,我也不想更改它.

某些代码: 这是到目前为止的jQuery

$('#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
  });

获得下一个Client_ID的PHP

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

感谢您的帮助!

解决方案

您只需要从uploadify.php文件中返回$ targetPath,就像这样-

echo $targetPath

请删除回显"1"

现在,您必须获取重命名的文件名.您可以在onUploadSuccess函数中获得此功能. onUploadSuccess()具有三个参数(文件,数据,响应),

其中file提供您在计算机中浏览过的文件的实际名称,而data提供您根据需要通过uploadify.php代码生成的重命名文件名.

因此您可以尝试以下代码-

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

我希望这会有所帮助.我的一位朋友告诉我,然后我完成了工作:)

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!!!

解决方案

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

这篇关于jQuery uploadify更改文件名,因为它正在上载.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆