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

使用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> 

图片转代码服务由CSDN问答提供 功能建议

我无法使用php上传文件,因为我无法将从html文件中获取的路径发送到 函数FTP_PUT,因为它只接受字符串“test.txt”

如何将路径发送到此函数

PHP文件

  $ file = $ _POST [“file”]; 
 
 //上传文件
if(ftp_put($ ftp_conn,$ file,$ file,FTP_BINARY))
 {\  n echo“已成功上传$ file。”; 
} 
else 
 {
 echo“上传$ file时出错。”; 
} 
 
 //关闭连接
ftp_close($ ftp_conn); 
 <  / code>  
 
 

HTML FILE

 &lt; div class =“container”&gt  ; 
 
&lt; div class =“row”&gt; 
&lt; div class =“col-lg-12”&gt; 
&lt; form class =“well”action =“Upload.php”method =  “post”&gt; 
&lt; div class =“form-group”&gt; 
&lt; label for =“file”&gt;选择要上传的文件&lt; / label&gt; 
  &lt; input type =“file”name =“file”id =“file”&gt; 
 
&lt;! - &lt; p class =“help-block”&gt;只有jpg,jpeg,png和gif文件 最大大小为1 MB是允许的。&lt; / p&gt;  - &gt; 
&lt; / div&gt; 
&lt; input type =“submit”class =“btn btn-lg btn-primary”value =“Upload”&gt; 
&lt; / form&gt; 
&lt;  / DIV&GT; 
&LT; / DIV&GT; 
&LT; / DIV&GT;  
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题