简体   繁体   中英

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? What should be the content of the file 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

$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");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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