使用PHP将图像从ftp位置复制到本地目录

使用PHP将图像从ftp位置复制到本地目录,php,Php,我正在尝试从ftp位置获取图像到本地目录,我有一个mysql表,其中ID和图像名称为列。我无法将图像从ftp位置复制到本地文件夹。该脚本连接到ftp服务器,获取图像并根据本地文件夹上的ID创建子目录,但无法写入图像 脚本: function etCommonGetImagePath($conn, $camName, $id) { $serverDir = $_SERVER['DOCUMENT_ROOT']; $imagesTop = "/cam_images"; $id

我正在尝试从ftp位置获取图像到本地目录,我有一个mysql表,其中ID和图像名称为列。我无法将图像从ftp位置复制到本地文件夹。该脚本连接到ftp服务器,获取图像并根据本地文件夹上的ID创建子目录,但无法写入图像

脚本:

function etCommonGetImagePath($conn, $camName, $id) {
    $serverDir = $_SERVER['DOCUMENT_ROOT'];
    $imagesTop = "/cam_images";

    $idArray = str_split(strval($id));
    $idString = implode('/', $idArray);

    $webPath = $imagesTop . "/" . $camName . "/" . $idString . ".jpg";
    $full_path = $serverDir . $webPath;

    if (file_exists($full_path)) {
        return $webPath;
    }
    else {
        $tableName = $camName;

        // Is there an image in the database?
        $sql = "SELECT image, datetime, image_name FROM $tableName WHERE id=$id";
        $result = $conn->Execute($sql);
        if (!$result) {
            print $conn->ErrorMsg();
        }
        $rows = $result->fields;
        $imageData = $rows['image'];
        $sightingDt = $rows['datetime'];
        $sightingTs = strtotime($sightingDt);
        $sightingFile = $rows['image_name'];
        if ($imageData != NULL) {
            // We have an image - copy it out to the filesystem
            chdir($serverDir.$imagesTop);
            if (!file_exists($camName)) {
                mkdir($camName);
            }y
            chdir($camName);
            foreach ($idArray as $dir) {
                if (!file_exists($dir)) {
                    mkdir($dir);
                }
                chdir($dir);
            }
            $imageFh = fopen($full_path, 'w');
            $numBytes = fwrite($imageFh, $imageData);--- this is where it fails.
            fclose($imageFh);
                } 
            } 

您能否更具体地说明无法写入图像的部分?有任何错误吗?没有,没有错误它无法将图像写入子目录,但根据ID创建它们。您是否可以使用
if(fwrite($imageFh,$imageData)==FALSE){
?能否更具体地说明写入映像部分失败的原因?是否有任何错误?不,没有错误它无法将映像写入子目录,但会根据ID创建子目录。是否可以使用
if(fwrite($imageFh,$imageData)==FALSE){