dshtze500055 2010-12-08 10:43
浏览 106
已采纳

如何在完成后从uploadify获取上传的文件详细信息

How should I retrieve the uploaded file details from uploadify after the completion of the upload process.

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

Updates

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>

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'];

?>
  • 写回答

2条回答 默认 最新

  • dousuiguang9328 2010-12-08 13:55
    关注

    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
    }
    

    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

    Updates

    As per your question updates, you have 2 options.

    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)

    in uploadify.php
    $_FILES['Filedata']['name'] //file name

    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;
    

    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"

    Getting parameters inside onComplete which are not available by default

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

    In my uploadify.php changed (this was in the original uploadify.php):-

    move_uploaded_file($tempFile,$targetFile);
    echo "1";
    

    to this:-

    move_uploaded_file($tempFile,$targetFile);
    echo $tempFile;
    

    and then inside the onComplete event did an explode -

    var tmpName = reponse;
    

    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;
    

    and then inside the onComplete event did an explode -

    var paramsArray = explode('%%__%%',reponse);
    param1 = paramsArray[0]; 
    param2 = paramsArray[1]; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题