2013-01-18 358 views
3

我制作了一个动态下拉文件上传系统,用户可以选择工程流,然后选择学期,然后选择主题,然后将文件上传到所需的目录中。这通常工作正常。 Working example检查文件路径链接,在不同文件夹中只上传两次图像或文档两次,以查看它是如何变化的。Uploadify文件上传和上传进度

然后我想显示文件上传进度,所以我下载并开始使用这个uploadify。并遇到以下问题。

两个问题在这里: 1)我单击选择文件,并选择一个文件的那一刻,该文件被上传,但我不能在任何地方找到它,虽然我已经设置了targetFolder 2)我想选择的路径首先,然后选择文件,然后单击上传(如示例中所示),然后我希望它上载到我从下拉列表中选择的指定目录中。

链接到演示:Uploadify Fail Example

这是我的代码:

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
     <title> SRMUARD - Upload </title> 
     <link rel="stylesheet" type="text/css" href="uploadify.css" /> 
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> 
     <script type="text/javascript" src="jquery.uploadify-3.1.min.js"></script> 
     <script type="text/javascript"> 
      $(function() { 
       $('#file_upload').uploadify({ 
        'swf'  : 'uploadify.swf', 
        'uploader' : 'uploadify.php', 
        'progressData' : 'speed', 
        'folder': <?php echo $targetFolder; ?> 
       }); 
      }); 
     </script> 
     <script type="text/javascript"> 
      function val() 
      { 
       if(document.uploads.three.selectedIndex == 0) 
       { 
        alert("Please choose all the appropriate options"); 
       } 
      } 
     </script> 
     <script> 
      $(function() { 
       $("#text-one").change(function() { 
       $("#text-two").load("textdata/" + $(this).val() + ".txt"); 
       }); 
       $("#text-two").change(function() { 
       $("#text-three").load("textdata/" + $(this).val() + ".txt"); 
       }); 
      }); 
     </script> 

    </head> 
    <body> 
     <div> 
      <form action="uploadify.php" method="POST" enctype="multipart/form-data" name="upload" id="upload"> 
       <label for="file">Choose a file: </label><br/> 

        <select id="text-one" name="one">     
         <option selected value="base">Select Department</option> 
         <option value="CSE" name="cse">Computer Science Engineering</option> 
         <option value="ECE" name="ece">Electronics & Communication Engineering</option> 
         <option value="MECH" name="mech">Mechanical Engineering</option>       
        </select><br/><br/> 
        <select id="text-two" name="two"> 
         <option>Select Semester</option> //Displays options dynamically using text files 
        </select><br/><br/>     
        <select id="text-three" name="three"> 
         <option>Select Subject</option> //Displays options dynamically using text files 
        </select><br/><br> 
        <input type="file" name="file_upload" id="file_upload" ><br/><br/> 
        <input type="submit" name="upload" id="submit" value="Upload" onClick="val()" />   
      </form> 
     <div> 
    </body> 
</html> 

这是我uploadify.php文件:

<?php 

    if(isset($_POST['upload'])) //checking if the path is set 
    { 
     $path1=$_POST['one']."/"; //path1 
     $path2=$_POST['two']."/"; //path2 
     $path3=$_POST['three']."/"; //path3 
     $targetFolder=$path1.$path2.$path3; //final path without the file 
    } 
    else 
    { 
     echo "Select a Subject"; 
     echo "<br>"; 
    } 


if (!empty($_FILES)) { 
    $tempFile = $_FILES['file_upload']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['file_upload']['name']; 
    // Validate the file type 
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions 
    $fileParts = pathinfo($_FILES['file_upload']['name']); 
    if (in_array($fileParts['extension'],$fileTypes)) { 
     move_uploaded_file($tempFile,$targetFile); 
     echo $targetFolder . '/' . $_FILES['file_upload']['name']; 
    } else { 
     echo 'Invalid file type.'; 
    } 
?> 

请帮我解决这个问题,让我秀进度条并将其上传到正确的目标文件夹。

谢谢

+0

http://www.uploadify.com/documentation看到这一点,也许有用 –

+0

阅读那些已经。 – trollster

+0

http://stackoverflow.com/questions/5563200/problem-in-sending-form-data-with-uploadify – oktapodi

回答

0

这plagin“uploadify”上传文件较早,那么你所选择的形式的元素。您可以在parametr这样添加数据“FORMDATA”:

$(function() { 
var one = $('#text-one').val(); 
var two = $('#text-two').val(); 
var one = $('#text-three').val(); 
$('#file_upload').uploadify({ 
'swf' : 'uploadify.swf', 
'uploader' : 'uploadify.php', 
'progressData' : 'speed', 
'formData': {'one':one,'two':'two','three':three}, 
'folder': 
}); 
}); 

答案会在事件“onUploadComplete”

+0

'文件夹'这里将取决于选择的选项的文件夹,我该如何解决? – trollster