完成后如何从uploadify获取上传的文件详细信息 [英] How can I get the uploaded file details from uploadify after completion
问题描述
完成上传过程后,我应该如何从uploadify检索上传的文件详细信息.
How should I retrieve the uploaded file details from uploadify after the completion of the upload process.
我想对上传的文件进行处理. 但是,当我使用uploadify时,它只是通过我自定义的uploadify.php将文件上传到某个位置. 我希望这个uploadify流程在完成文件的详细信息(例如文件名和目标位置)之后重定向到页面,在该位置我将继续对上传的文件进行第二次操作
I want to do a process in the uploaded file. But when I use the uploadify it simply uploads the file to a location through the uploadify.php which I customized. I want this uploadify process to redirect to a page after completed with the details of the file such as filename and the targeted location where I will proceed with my second operation on the file uploaded
更新
这是我到目前为止的代码
This is what my code as of now
<style type="text/css">
body {
font: 0.8em/1.6em Arial, Helvetica, sans-serif;
}
fieldset {
width: 500px;
}
#sample {
display:table;
}
#sampleFile {
float: left;
display:table-cell;
margin-right: 15px;
}
#download {
margin-top: 15px;
display: table;
}
.dlImage {
display: table-cell;
float: left;
margin-right: 10px;
}
.dlText {
float: left;
display: table-cell;
}
.fileDetails {
color: red;
}
.releaseDate{
margin-top: -3px;
color: gray;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Uploadify scriptData Sample</title>
<link rel="stylesheet" href="uploadify/uploadify.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.uploadify.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#fileUpload").fileUpload({
'uploader': 'uploadify/uploader.swf',
'cancelImg': 'uploadify/cancel.png',
'script': 'uploadify/upload.php',
'folder': 'files',
'multi': false,
'displayData': 'speed',
'onComplete' : function(event, queueID, fileObj, reponse, data) {
location.href="complete.php";
}
});
});
</script>
</head>
<body>
<div id="sample">
<div id="sampleFile">
<fieldset style="border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0">
<legend><strong>Sélectionner l'image à imprimer :</strong></legend>
<div id="fileUpload">You have a problem with your javascript</div>
<a href="javascript:$('#fileUpload').fileUploadStart()">Start Upload</a> <p></p>
</fieldset>
</div>
</body>
</html>
在第二页上,我确实想回显上载的文件名 我在第二页的complete.php中找到了
on the second page I do want to echo the file name that is uploaded I have there in the second page complete.php
<?php
print_r($_FILES);
echo $_FILES['type'];
echo $_FILES['tmp_name'];
echo $_FILES['name'];
echo $_FILES['size'];
?>
推荐答案
您知道您可以像这样在onComplete
事件中获取filename
,filpath
吗:-
Do you know that you can get the filename
, filpath
inside the onComplete
event like this:-
onComplete: function(event, queueID, fileObj, reponse, data)
{
alert fileObj.name; //The name of the uploaded file
alert fileObj.filePath; //The path on the server to the uploaded file
location.href= "complete.php?filename="+fileObj.name+"&filepath="+fileObj.filePath; //Here you can do a javascript redirect
}
检查文档以获取更多详细信息 http://www.uploadify.com/documentation/events/oncomplete-2/
Check the documentation for further details http://www.uploadify.com/documentation/events/oncomplete-2/
您在寻找那些价值吗?如果没有让我知道
Are you looking for those values? If not let me know
更新
根据您的问题更新,您有2个选项.
As per your question updates, you have 2 options.
在uploadify.php中上传文件后,执行某些过程".您可以看到uploadify插件随附的文件uploadify.php
.在那里,您有一个$_FILES['Filedata']
数组,其中包含所有文件信息.您可以在这里自己进行后期处理(通过更好地调用函数,而不是在uploadify的核心代码中编写大量代码)
Either to do the "some process" after the file upload in the uploadify.php. You can see the file uploadify.php
which comes with the uploadify plugin. There you have the $_FILES['Filedata']
array containing all the file info. You may do the post processing here itself (by calling a function better instead of writing lots of code in uploadify's core code)
在uploadify.php中
$ _FILES ['Filedata'] ['name']//文件名
in uploadify.php
$_FILES['Filedata']['name'] //file name
或者像我说的那样,获取onComplete
事件中的文件名和路径.然后像这样传递这些参数:-
Or like I said, get the file name and path inside the onComplete
event. Then pass these params like this :-
location.href= "complete.php?filename="+fileObj.name+"&filepath="+fileObj.filePath;
我认为这更好.您可以发送ajax请求来执行整个过程(文件上传+某些过程"),而无需再次加载页面.
使用这些参数在onComplete
事件内编写一个 $ .post()请求,并将其发布到"complete.php"
I think this is better. You may send an ajax request instead to do the entire process (file upload + your "some process") without loading the page again.
Write a $.post() request inside the onComplete
event with those parameters and post to "complete.php"
在onComplete
内部获取默认情况下不可用的参数
Getting parameters inside onComplete
which are not available by default
您必须使用onComplete
内部可用的response
参数
我使用的是uploadify版本2.1.0,因此我的解决方案肯定可以在该版本上运行.
如果只需要一个参数,则可以在uploadify.php
的末尾回显该参数.
我做了以下事情:-
You have to use the response
parameter available inside onComplete
I worked on uploadify version 2.1.0 so my solution will work for sure on that version.
If you want only one parameter, you can echo that at the end of uploadify.php
I did the following thing:-
在我的uploadify.php
中进行了更改(这是在原始的uploadify.php中):-
In my uploadify.php
changed (this was in the original uploadify.php):-
move_uploaded_file($tempFile,$targetFile);
echo "1";
对此:-
move_uploaded_file($tempFile,$targetFile);
echo $tempFile;
,然后在onComplete
事件内部发生爆炸-
and then inside the onComplete
event did an explode -
var tmpName = reponse;
但是,如果您想在onComplete
中获得多个参数,这是我可以提供的一个技巧(这不是一个好方法,但是我无法通过其他任何方式返回多个参数-我尝试过返回json数组等):-
If however, you want to get more than one parameter inside onComplete
, this is a trick I can give (this is not a good approach, but I was not able to return multiple params by any other way - I tried returning json array etc.):-
move_uploaded_file($tempFile,$targetFile);
echo $param1.'%%__%%'.$param2;
,然后在onComplete
事件内部发生爆炸-
and then inside the onComplete
event did an explode -
var paramsArray = explode('%%__%%',reponse);
param1 = paramsArray[0];
param2 = paramsArray[1];
这篇关于完成后如何从uploadify获取上传的文件详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!