簡體   English   中英

上傳圖片到FTP

[英]Upload image to FTP

從我的Swift應用程序中,我將圖像文件發送到我的PHP腳本中,並且想要從我的PHP腳本中將其上傳到我的FTP中。

這是我的劇本

<?php

$ftp_server = "My FTP";
$ftp_user = "Username";
$ftp_pass = "Password";
$file = $_FILES["file"]["tmp_name"];
$remote_file = "test.png"; 

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_user\n";
}

// upload a file 
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) { 
    echo "Successfully uploaded $file\n"; 
    exit; 
} 
else { 
    echo "There was a problem while uploading $file\n"; 
    exit; 
} 

// close the connection
ftp_close($conn_id);  
?>

我正在連接到服務器,並且可以上傳文件,但是我的問題是我上傳的文件已損壞。 我認為這與我的$remote_file = "test.png"; 使用ftp_put上傳文件是正確的方法嗎?有人知道它為什么損壞嗎?

<?php

$ftp_server = "My FTP";
$ftp_user = "Username";
$ftp_pass = "Password";
$file = $_FILES["file"]["tmp_name"];
$remote_file = "test.png"; 

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_user\n";
}

// upload a file 
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) { 
    echo "Successfully uploaded $file\n"; 
    exit; 
} 
else { 
    echo "There was a problem while uploading $file\n"; 
    exit; 
} 

// close the connection
ftp_close($conn_id);  
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM