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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀