Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-上传输入=";文件";图像到ftp目录并显示图像的直接链接_Php_Image_File_Input_Ftp - Fatal编程技术网

PHP-上传输入=";文件";图像到ftp目录并显示图像的直接链接

PHP-上传输入=";文件";图像到ftp目录并显示图像的直接链接,php,image,file,input,ftp,Php,Image,File,Input,Ftp,我正试图使这种非常简单的图像托管网站。 我正在使用下面的代码将图像从input=“file”上传到我的ftp目录。下一步是在上传到另一个页面后立即显示直接图像链接(例如:www.example.com/123.png) <?php $ftp_server = "myftp.co.uk"; $ftp_user_name = "myusername"; $ftp_user_pass = "mypass"; $destination_file = "/public_html/m

我正试图使这种非常简单的图像托管网站。 我正在使用下面的代码将图像从
input=“file”
上传到我的ftp目录。下一步是在上传到另一个页面后立即显示直接图像链接(例如:www.example.com/123.png)

<?php

  $ftp_server = "myftp.co.uk";
  $ftp_user_name = "myusername";
  $ftp_user_pass = "mypass";
  $destination_file = "/public_html/my/directory/";
  $source_file = $_FILES['file']['tmp_name']; 

  // set up basic connection
  $conn_id = ftp_connect($ftp_server);
  ftp_pasv($conn_id, true); 

  // login with username and password
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

  // check connection
  if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
    exit; 
  } else {
    echo "Connected to $ftp_server, for user $ftp_user_name";
  }

  // upload the file
  $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

  // check upload status
  if (!$upload) { 
    echo "FTP upload has failed!";
  } else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
  }

  // close the FTP stream 
  ftp_close($conn_id);

?>


我不知道怎么做。我到处都查过了,找不到一个地方解释怎么做。

为什么要使用FTP?简单移动上传的文件应该可以!有什么原因吗?可能是重复的:?