在php中通过ftp上传时图像损坏[duplicate]

lpwwtiir  于 2023-02-21  发布在  PHP
关注(0)|答案(1)|浏览(164)

此问题在此处已有答案

ftp_put is corrupting my movies after transfer, is it wrong?(1个答案)
3天前关闭。
我正在做一个自学成才的本地项目,并试图上传一个文件到服务器。
但当我上传图像文件时,它被损坏了。
这是我的博客

<?php
$ds          = DIRECTORY_SEPARATOR;  //1

$storeFolder = 'uploads';   //2

if (!empty($_FILES)) {

$tempFile = $_FILES['file']['tmp_name'];          //3             

$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4

$targetFile =  $targetPath. $_FILES['file']['name'];  //5

move_uploaded_file($tempFile,$targetFile); //6

$ftp_server="myServer";
$ftp_user_name="userName";
$ftp_user_pass="Password";

$file = $targetFile;//tobe uploaded
$remote_file = $_FILES['file']['name'];

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

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

// 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);

}
?>

它目前上传到本地文件夹Uploads也到服务器,但损坏的任何帮助,这将是伟大的。

wljmcqd8

wljmcqd81#

你试过使用FTP二进制文件吗?图像是二进制文件而不是ASCII文件.

相关问题