试图从index.php上的文本框中获取价值并在upload.php

时间:2015-04-23 17:55:47

标签: javascript php file-upload

我们有一个简单的上传应用程序,只是尝试使用FTP将文件上传到某个位置,但在上传文件之前,我们希望用户输入文件夹的名称,我们将创建此文件夹,然后将文件放入其中。我们可以成功地输入静态值,但我们需要从index.php上的文本框'foldername'中提取文本,并在upload.php上使用foldername的值,并且在POST或GET方面没有成功。任何帮助都会很棒。

的index.php

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image upload</title>
<link href='http://fonts.googleapis.com/css?family=Boogaloo'  rel='stylesheet' type='text/css'>
<script  src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="js/multiupload.js"></script>
<script type="text/javascript">
var config = {
    support :  "image/jpg,image/png,image/bmp,image/jpeg,image/gif,text/plain,text/anytext,application/csv",        // Valid file formats
form: "demoFiler",                  // Form ID
dragArea: "dragAndDropFiles",   // Upload Area ID
uploadUrl: "upload.php"             // Server side upload url
}
$(document).ready(function(){
initMultiUploader(config);
});
</script>
<link href="css/style.css" type="text/css" rel="stylesheet" />
</head>
<body lang="en">
<center><h1 class="title">Multiple Drag and Drop File Upload</h1></center>
<div id="dragAndDropFiles" class="uploadArea">
<h1>Drop Images Here</h1>
</div>
<form method="POST" name="demoFiler" id="demoFiler" enctype="multipart/form-data" action="upload.php" >
Please name your folder: <input type="text" name="foldername" id="foldername"/></br>
<input type="file" name="multiUpload" id="multiUpload" multiple />
<input type="submit" name="submitHandler" id="submitHandler" value="Upload" class="buttonUpload" />
</form>
<div class="progressBar">
<div class="status"></div>
</div>
</body>
</html>

upload.php的

<?php
$newdir = $_POST['foldername'];
$dir = '/1';
$connect = ftp_connect('server');
ftp_login($connect, 'user', 'password');
ftp_pasv($connect, true);
ftp_chdir($connect, $dir);
if($_SERVER['REQUEST_METHOD'] == "POST"){
    if (@ftp_chdir($connect, $newdir)){
         if (!empty($_FILES)) {
        $tempFile = $_FILES['file']['tmp_name'];          //3             
        $targetFile =  $_FILES['file']['name'];  //5
        ftp_put($connect, $targetFile, $tempFile, FTP_ASCII);
            }   

        }
        else
        {
        ftp_mkdir($connect, $newdir);
        ftp_chdir($connect, $newdir);
         if (!empty($_FILES)) 
            {
            $tempFile = $_FILES['file']['tmp_name'];          //3             
            $targetFile =  $_FILES['file']['name'];  //5
            ftp_put($connect, $targetFile, $tempFile, FTP_ASCII);
            }
        }


}
ftp_close($connect);

    echo($_POST['index']);
    exit;

?>

1 个答案:

答案 0 :(得分:0)

解决方法是在multiupload.js中你需要在_uploader函数中添加一行:

data.append('index',ids');
data.append('foldername', $('#foldername').val());

foldername行是您需要添加的行,应该是基于github版本的第72行。