开发者

PhP ftp put error message: failed to open stream

Am trying to upload an image from my local machine (PC) to the FTP server. In return, received the following error:

Warning: ftp_put(c:/dhimage/DSC_0067.JPG) [function.ftp-put]: failed to open stream: No such file or directory in /home/dxxx/public_html/ftp/test.php on line 37 Cannot upload

Here's my code:

// get FTP access parameters

$host = 'ftp.xxx.com';

$user = 'abcxxx';

$pass开发者_Python百科 = 'xxxxx';



$local_file = 'c:/dhimage/DSC_0067.JPG';
$ftp_file = 'DSC_0067.JPG';


// open connection
$conn = ftp_connect($host) or die ("Cannot initiate connection to host");

// send access parameters
ftp_login($conn, $user, $pass) or die("Cannot login");

// perform file upload
$upload = ftp_put($conn, $ftp_file, $local_file, FTP_BINARY);

// check upload status

// display message

if (!$upload) {

    echo "Cannot upload";

} else {

    echo "Upload complete";

}

// close the FTP stream

ftp_close($conn);


I think you are misunderstanding something here. The PHP script is running on the server. It has no access to your local files.

The most common way to solve this is to do a file upload from your local machine through a HTML page. For that, see the PHP manual on file uploads.

Alternatively, if your machine and the server are in the same local network, you may be able to access your client PC's files through a network share. But we don't know enough about your setup to tell.


The error is pretty much self-explanatory, make sure that:

  • You are specifying the correct path
  • Directory dhimage has read permissions.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜