0
我們有一個簡單的上傳應用程序,只是嘗試使用FTP將文件上傳到某個位置,但在上傳我們希望用戶輸入的文件之前文件夾的名稱,我們將創建該文件夾,然後將文件放入其中。我們可以成功地輸入靜態值,但是我們需要從index.php上的文本框'foldername'中取出文本,並使用upload.php中的foldername值,並且POST或GET沒有成功。任何幫助都會很棒。試圖從index.php的文本框中獲取價值並在upload.php上使用它
的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;
?>
當您嘗試此操作時會發生什麼?你可以在設置$ newDir之後做一個簡單的回聲以確保它有一個值嗎?另外,我會對名稱進行一些清理,以便它是一個有效的目錄名稱。 – mbeintema
當我們運行這個時,它沒有得到$ newDir的任何值。 –
這個問題似乎涉及多上傳我會想,B/C只是使用該表格,並將其發佈到upload.php我能夠得到的價值沒有問題 – mbeintema