简体   繁体   English

使用FTP上传PHP中的表单文件

[英]Upload with FTP a form file in PHP

I have this form: 我有这个表格:

<form action="after.php" method="post" id="divulgacao">
    <div style="float: left;width: 195px; margin-right: 10px;">
        <p class="pdados">Your name</p>
        <input class="campodivulgue" name="titulo" type="text" />
    </div>
    <div style="float: left;width: 195px; margin-right: 10px;">
        <p class="pdados">E-mail</p>
        <input class="campodivulgue" name="email" type="text" />
    </div>
    <div style="float: left; width: 195px; ">
        <p class="pdados">Your picture</p>
        <input style="float:left; height: 22px;"  type="file" name="file" id="file" />
    </div>                  
    <p align="right" style="margin-top: 10px;"><input class="btn" type="submit" name="button" id="button" value="Send" /></p>                       
</form>

What should I do so when the user clicks on the send button, the chosen file in the file field is uploaded using FTP? 当用户单击发送按钮,使用FTP上传文件字段中的选定文件时,我该怎么办? What should be the content of the file after.php after.php文件的内容应该是什么

Do I have to put another form for file upload? 我是否需要填写其他表格进行文件上传?

您需要在表单中声明enctype属性。

<form action="after.php" method="post" id="divulgacao" enctype="multipart/form-data">

example contents for after.php taken right from PHP Manual after.php的示例内容直接取自PHP Manual

$uploads_dir = '/uploads';
foreach ($_FILES["file"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["file"]["tmp_name"][$key];
        $name = $_FILES["file"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM