upload a file using FTP and php

淺唱寂寞╮ 提交于 2019-12-02 09:20:20

Use $_FILES["file"]["tmp_name"] instead of $_POST["file"]

edit:

$file = $_FILES["file"]["tmp_name"];
$file_name = $_FILES["file"]["name"];

// upload file
if (ftp_put($ftp_conn, $file_name, $file, FTP_BINARY))

or move the uploaded file first:

$target_path = "uploads/".basename($_FILES["file"]["name"]); 
move_uploaded_file($_FILES["file"]["tmp_name"], $target_path);

Change your form tag to :

<form class="well" action="Upload.php" method="post"  enctype="multipart/form-data">

If you don't include

enctype="multipart/form-data"

Nothing will get uploaded!

Check that the path is correct... I don't know your file structure so I'm guessing you need the full path, try...

 if (ftp_put($ftp_conn, getcwd().$file, $file, FTP_BINARY)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!