Advertisement
artursn

Untitled

Jan 13th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. if (isset ( $postData ['image_'] ) && $postData ['image_'] ['error'] == 0) {
  2. $adapter = new Http ();
  3. $fileName = $postData ['image_'] ['name'];
  4. $extension = pathinfo ( $fileName, PATHINFO_EXTENSION );
  5.  
  6. $name = 'image_' . $id;
  7.  
  8. $uploadPath = sprintf ( '/upload/product/%d/%d/', substr ( $id, strlen ( $id ) - 2, 2 ), substr ( $id, strlen ( $id ) - 4, 2 ) );
  9. if (! is_dir ( APPLICATION_PATH . $uploadPath )) {
  10. mkdir ( APPLICATION_PATH . $uploadPath, 0755, true );
  11. }
  12. $renameOptions ['target'] = APPLICATION_PATH . $uploadPath . $name . '.' . $extension;
  13. $filters = array ();
  14. $filters [] = new Rename ( $renameOptions );
  15. $adapter->setFilters ( $filters );
  16. if ($adapter->isValid ()) {
  17. $adapter->receive ();
  18. }
  19. $product->image = $uploadPath . $name . '.' . $extension;
  20. $this->getService ()->getEntityManager ()->persist ( $product );
  21. $this->getService ()->getEntityManager ()->flush ();
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement