douchui1657 2015-12-25 19:16
浏览 35
已采纳

使用FTP和php上传文件

I can't Upload the file using php because i can't send the path i got from the html file to the function FTP_PUT because it only takes string "test.txt"

How Can i send the Path to this function

PHP FILE

$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 FILE

    

<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> 
  • 写回答

3条回答 默认 最新

  • duangao7133 2015-12-25 20:05
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答