uploadify php 重命名,自定义uploadify服务器端上传脚本

服务器端上传脚本是用于上传文件的后台程序。下面是基于PHP自定义服务器端上传脚本的一些信息。

传递额外的数据传递到服务器

根据method方式(post或get),额外的数据作为查询字符串附加到上传参数中,或通过参数formdata选项传送。服务器端通过$_POST或$_GET得到formData。

初始化Uploadify:

$('#file_upload').uploadify({

// Some options

'method' : 'post',

'formData' : { 'someKey' : 'someValue' }

});

在服务器端脚本中:

// Set $someVar to 'someValue'

$someVar = $_POST['someKey'];

如果你希望保存不同的文件名,这是非常有用的。如果你想在上传开始前在页面上设置些信息,最好是在onUploadStart事件中使用settings方法在上传前设置好formData。

从服务器端返回数据

任何在uploadify.php脚本中输出的内容都可以通过onUploadSuccess事件中的第二个参数得到。

从uploadify.php中返回文件名:

$targetFolder = '/uploads'; // Relative to the root

if (!empty($_FILES)) {

$tempFile = $_FILES['Filedata']['tmp_name'];

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;

$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

// Validate the file type

$fileTypes = array('jpg','jpeg','gif','png'); // File extensions

$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {

move_uploaded_file($tempFile,$targetFile);

echo $targetFolder . '/' . $_FILES['Filedata']['name'];

} else {

echo 'Invalid file type.';

}

}

在onUploadSuccess中接收返回的数据:

$('#file_upload').uploadify({

// Some options

'onUploadSuccess' : function(file, data, response) {

alert('The file was saved to: ' + data);

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值