diff --git a/.gitignore b/.gitignore index 8493874..3231536 100644 --- a/.gitignore +++ b/.gitignore @@ -1,71 +1,72 @@ #ignore pling-music and pling-books */pling-books-html5/* */pling-music-html5/* #ignore store specific images */images_sys/store_*/ #ignore eclipse files .buildpath .project .settings/* #ignore PHPStorm Files .idea/* #ignore local Vagrant dir .vagrant/* #ignore local tmp dir */.tmb/* #ignore local dir local/* phing/* *.local* --.htaccess* .htaccess* .htpasswd* *.orig *.tsm *.ova */.well-known loadstorm-41440.html mu-2cc5c638-f7c471ad-be42f5c0-99b8cf30.txt mu-9ff52416-7b5ae544-c8bac39d-dc810a54 #ignore thumbnails created by windows Thumbs.db #Ignore files build by Visual Studio *.obj *.exe *.pdb *.user *.aps *.pch *.vspscc *_i.c *_p.c *.ncb *.suo *.tlb *.tlh *.bak *.cache *.ilk *.log [Bb]in [Dd]ebug*/ *.lib *.sbr obj/ [Rr]elease*/ _ReSharper*/ [Tt]est[Rr]esult* httpdocs/src/status.jsx +.idea/ diff --git a/image_bucket_upload.php b/image_bucket_upload.php index 475f240..e92967d 100644 --- a/image_bucket_upload.php +++ b/image_bucket_upload.php @@ -1,91 +1,112 @@ . **/ // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__))); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); defined('IMAGES_UPLOAD_PATH') || define('IMAGES_UPLOAD_PATH', APPLICATION_PATH . '/img/'); // Ensure library/ is on include_path set_include_path(implode("/", array( APPLICATION_PATH . '/../library', get_include_path(), ))); +$_mime_type = array( + 'image/jpeg' => '.jpg', + 'image/jpg' => '.jpg', + 'image/png' => '.png', + 'image/gif' => '.gif', + 'application/x-empty' => '.png' +); + require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader->setFallbackAutoloader(true); +$log = new Zend_Log(); +$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH .'/data/logs/msg_' . date("Y-m-d") . '.log'); +$log->addWriter($writer); + +$log->debug('_POST: ' . print_r($_POST, true)); +$log->debug('_FILES: ' . print_r($_FILES, true)); + $upload = new Zend_File_Transfer_Adapter_Http(); -$upload->addValidator('Count', false, 1); -$upload->addValidator('IsImage', false); -$upload->addValidator('Size', false, array('min' => '2kB', 'max' => '2MB')); +$upload->addValidator('Count', false, 1) + ->addValidator('IsImage', false) + ->addValidator('Size', false, 5097152) + ->addValidator('FilesSize', false, 5097152); + //$upload->addValidator('ImageSize', false, // array( // 'minwidth' => 50, // 'maxwidth' => 2000, // 'minheight' => 50, // 'maxheight' => 2000 // ) //); -$_mime_type = array( - 'image/jpeg' => '.jpg', - 'image/jpg' => '.jpg', - 'image/png' => '.png', - 'image/gif' => '.gif', - 'application/x-empty' => '.png' -); +if (false === $upload->isValid()){ + $log->err('isValid errors: ' . print_r($upload->getErrors(), true)); + $log->info('isValid messages: ' . print_r($upload->getMessages(), true)); + + header("HTTP/1.0 500 Server Error"); + print implode("\n
", $upload->getMessages()); + exit(0); +} //create buckets $fileHash = $upload->getHash('sha1'); $destBucketPath = substr_replace($fileHash, '/', 1, 0); $destBucketPath = substr_replace($destBucketPath, '/', 3, 0); $destBucketPath = substr_replace($destBucketPath, '/', 5, 0); $destBucketPath = substr_replace($destBucketPath, '/', 7, 0); $destPath = IMAGES_UPLOAD_PATH . $destBucketPath . $_mime_type[$upload->getMimeType()]; $dir = dirname($destPath); if (!file_exists($destPath) and !is_dir($dir)) { mkdir($dir, 0777, true); } $upload->addFilter('Rename', array('target' => $destPath, 'overwrite' => true)); if (false === $upload->receive()) { + $log->err('receive errors: ' . print_r($upload->getErrors(), true)); + $log->info('receive messages: ' . print_r($upload->getMessages(), true)); + header("HTTP/1.0 500 Server Error"); print implode("\n
", $upload->getMessages()); exit(0); } header("HTTP/1.0 200 OK"); print $destBucketPath . $_mime_type[$upload->getMimeType()];