我无法使用php上传文件,因为我无法将从html文件获取的路径发送到函数FTP_PUT,因为它只需要字符串“test.txt”
如何将路径发送到此功能
PHP文件
$file = $_POST["file"];
// upload file
if (ftp_put($ftp_conn, $file, $file, FTP_BINARY))
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
// close connection
ftp_close($ftp_conn);
HTML文件
<div class="container">
<div class="row">
<div class="col-lg-12">
<form class="well" action="Upload.php" method="post" >
<div class="form-group">
<label for="file">Select a file to upload</label>
<input type="file" name="file" id="file">
<!-- <p class="help-block">Only jpg,jpeg,png and gif file with maximum size of 1 MB is allowed.</p> -->
</div>
<input type="submit" class="btn btn-lg btn-primary" value="Upload">
</form>
</div>
</div>
</div>
答案 0 :(得分:1)
使用$_FILES["file"]["tmp_name"]
代替$_POST["file"]
编辑:
$file = $_FILES["file"]["tmp_name"];
$file_name = $_FILES["file"]["name"];
// upload file
if (ftp_put($ftp_conn, $file_name, $file, FTP_BINARY))
或先移动上传的文件:
$target_path = "uploads/".basename($_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"], $target_path);
答案 1 :(得分:0)
将表单标记更改为:
<form class="well" action="Upload.php" method="post" enctype="multipart/form-data">
如果你不包括
enctype="multipart/form-data"
什么都不会上传!
答案 2 :(得分:0)
检查路径是否正确...我不知道您的文件结构,所以我猜测您需要完整路径,请尝试...
if (ftp_put($ftp_conn, getcwd().$file, $file, FTP_BINARY)