bradgrafelman;10982611 wrote:Can you show us the PHP script that's doing all of this uploading and subsequent DB queries?
Not easily - it's all pretty modular OO stuff, but I can throw a few parts of it up...
Here's the func that runs the image uploading:
public function uploadImageRemote($photoSizeArray, $publicPath = NULL)
{
if (!empty($_FILES['filename']['tmp_name']))
{
require_once(CORE_FILE_INCLUDE_PATH . 'uploadImage.class.php');
$this->fieldarray['itemId'] = $this->fieldarray['orderItemId'];
$this->fieldarray['imageType'] = 'order';
$upload = new uploadImage($this->fieldarray, $photoSizeArray);
if (!empty($publicPath))
{
$upload->setPathPrefix('');
}
if (!$this->filename = $upload->upload()) // the functionality in here (resizing, thumbnailing) is bypassed for large file uploads
{
return 'Error: possible file upload attack!';
}
else
{
if ($upload->uploadRemoteFtp($this->filename)) // this seems to work fine
{
$data = new db_OrderItems();// beginning of the post-FTP db update that ends up failing
$data->setSelect('orderItemId, photos');
$data->setWhere('orderItemId=' . $this->fieldarray['itemId']);
$pRow = $data->getSingle();
if (!empty($pRow['photos']))
{
$photos = unserialize($pRow['photos']);
}
else
{
$photos = array();
}
$photo = array(
'photoId' => time(),
'slot' => $this->fieldarray['photoSlot'],
'filename' => $this->filename,
'fullsizeFileOrderItemId' => $this->fieldarray['itemId'],
'fullsizeFilePath' => PHOTO_SERVER_UPLOAD_DIR . '/' . $this->fieldarray['itemId'] . '/' . $this->filename
);
if ($dim = $upload->getImageDimensions())
{
$photo['width'] = $dim['width'];
$photo['height'] = $dim['height'];
}
$photos[] = $photo;
$pRow['photos'] = serialize($photos);
$data->updateRecord($pRow); // this is what fails
}
}
}
else
{
$this->filename = $this->fieldarray['filename'];
}
}
Here's the actual FTP transfer process:
public function uploadRemoteFtp($filename)
{
if ($conn = ftp_connect(PHOTO_SERVER))
{
if (ftp_login($conn, PHOTO_SERVER_USER, PHOTO_SERVER_PW))
{
ftp_pasv($conn, true);
if (ftp_chdir($conn, PHOTO_SERVER_UPLOAD_DIR))
{
$sourceFile = $this->pathPrefix . 'photos/' . $this->fieldarray['imageType'] . '/original/' . $this->fieldarray['itemId'] . '/' . $filename;
if ($dims = getimagesize($sourceFile))
{
$this->dimensions['width'] = $dims[0];
$this->dimensions['height'] = $dims[1];
}
$image_dir = $this->fieldarray['itemId'];
$rawList = ftp_nlist($conn, ".");
if (!in_array($image_dir, $rawList))
{
ftp_mkdir($conn, $image_dir);
//@ftp_chmod($conn, 0777, $image_dir);
}
ftp_chdir($conn, $image_dir);
if (ftp_put($conn, $filename, $sourceFile, FTP_BINARY))
{
unlink($sourceFile);
return true;
}
else
{
return 'Error uploading photo';
}
}
}
else
{
return 'Error: imageserver login error';
}
}
else
{
return 'Error: imageserver connect error';
}
}