<?php require_once __DIR__ . '/../vendor/autoload.php'; $memoryStorage = new \SimplePhoto\Storage\MemoryStorage(); $memoryDataStore = new \SimplePhoto\DataStore\MemoryDataStore(); $storageManager = new \SimplePhoto\StorageManager(); $storageManager->add('memory', $memoryStorage); $storageManager->setDefault('memory'); $simplePhoto = new \SimplePhoto\SimplePhoto($storageManager, $memoryDataStore); // Upload // $id = $simplePhoto->upload(new \SimplePhoto\Source\UrlSource('http://localhost/cdn/images/728X90.jpg')); var_dump($id); $photo = $simplePhoto->get($id); $resize = $simplePhoto->get($id, array('transform' => array('size' => array(50, 50)))); var_dump($resize); ?> <?php if ($photo) { ?> <img src="<?php echo $photo->url(); ?> " /> <br /> <img src="<?php echo $resize->url(); ?> " /> <?php }
<?php require_once __DIR__ . '/../vendor/autoload.php'; // 1. Storage Manager $storageManager = new \SimplePhoto\StorageManager(); // Create local storage $localStorage = new \SimplePhoto\Storage\LocalStorage(array('root' => __DIR__, 'path' => './files/photos')); // Create remote host storage $remoteStorage = new \SimplePhoto\Storage\RemoteHostStorage(array('path' => 'photos', 'host' => '127.0.0.1', 'port' => 21, 'username' => 'morrelinko', 'password' => '123456', 'root' => '/', 'url' => 'http://localhost/project/packages')); // Add local storage to storage manager $storageManager->add('local', $localStorage); // Add remote storage to storage manager $storageManager->add('static_host', $remoteStorage); // Set fallback storage that loads default photos for invalid/not found photos $storageManager->setFallback(new \SimplePhoto\Storage\LocalStorage(array('root' => __DIR__, 'path' => './files/defaults'))); // 2. Data Store $dataStore = new \SimplePhoto\DataStore\SqliteDataStore(array('database' => 'sample_app.db')); // Not Required.. $dataStore->getConnection()->exec("\n CREATE TABLE IF NOT EXISTS photos (\n id INTEGER PRIMARY KEY,\n storage_name TEXT NOT NULL,\n file_name TEXT NOT NULL,\n file_extension TEXT NOT NULL,\n file_size TEXT NOT NULL DEFAULT 0,\n file_path TEXT NOT NULL,\n file_mime TEXT NOT NULL,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\n );\n"); // Create an instance of simple photo and return it.. return new \SimplePhoto\SimplePhoto($storageManager, $dataStore);