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);
}
});
總結
以上是生活随笔為你收集整理的uploadify php 重命名,自定义uploadify服务器端上传脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 增值税防伪税控系统到底是什么呢?
- 下一篇: 下载腾讯视频(mp4 格式)