我正在尝试将图像从ftp位置获取到本地目录,我有一个带有ID和图像名称的mysql表作为列。我无法将图像从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);
}
}