使用PHP上载和下载时出现FTP文件名和路径错误
我正在尝试使用PHP实现文件传输 我得到以下错误:-使用PHP上载和下载时出现FTP文件名和路径错误,php,file-upload,download,ftp,filepath,Php,File Upload,Download,Ftp,Filepath,我正在尝试使用PHP实现文件传输 我得到以下错误:- 使用Html表单上载文件。使用PHP文件获取文件 $\u文件。如何从中获取扩展名为的原始文件名 php对象?basename方法提供了不同的名称。 我试着上传一个.txt文件。它被转换成php文件并 上传到服务器上 在下载部分,我使用的是ftp\u-get。我想把这个文件拿出来 下载到我的笔记本电脑上。但是,它会保存在服务器上 它本身具有我在$fileToy中指定的整个路径。无误 显示,并且文件未下载。为了简单起见 我直接给出了路径,因为我上
ftp\u-get
。我想把这个文件拿出来
下载到我的笔记本电脑上。但是,它会保存在服务器上
它本身具有我在$fileToy
中指定的整个路径。无误
显示,并且文件未下载。为了简单起见
我直接给出了路径,因为我上传了一个.txt文件if ((isset($_FILES['myfile']['tmp_name'])))
$myfile = $_FILES['myfile']['tmp_name'];
else echo "upload not possible";
$fileFrom = $myfile;
$fileTo = 'photos/'. basename($myfile); //photos is directory created on server
echo $fileTo;
$ftpObj -> uploadFile($fileFrom, $fileTo);
$fileFrom = $fileTo ; # The location on the server
$fileToy = 'Downloads\techppr.txt' ; # Local dir to save to
// *** Download file
$ftpObj->downloadFile($fileFrom, $fileToy);
public function uploadFile ($fileFrom, $fileTo)
{
// *** Set the transfer mode
$asciiArray = array('txt', 'csv');
$extension = end(explode('.', $fileFrom));
if (in_array($extension, $asciiArray)) {
$mode = FTP_ASCII;
} else {
$mode = FTP_BINARY;
}
// *** Upload the file
$upload = ftp_put($this->connectionId, $fileTo, $fileFrom, $mode);
}
public function downloadFile ($fileFrom, $fileTo)
{
// *** Set the transfer mode
$asciiArray = array('txt', 'csv');
$extension = end(explode('.', $fileFrom));
if (in_array($extension, $asciiArray)) {
$mode = FTP_ASCII;
} else {
$mode = FTP_BINARY;
}
if (ftp_get($this->connectionId, $fileTo, $fileFrom, $mode, 0)) {
return true;
$this->logMessage(' file "' . $fileTo . '" successfully downloaded');
} else {
return false;
$this->logMessage('There was an error downloading file "' . $fileFrom . '" to "' . $fileTo . '"');
}
}