@@ -71,7 +71,7 @@ |
||
71 | 71 | |
72 | 72 | public function generatePathFromSecretKey($secretKey) |
73 | 73 | { |
74 | - if($secretKey == '') |
|
74 | + if($secretKey == '') |
|
75 | 75 | return ''; |
76 | 76 | |
77 | 77 | $mimeType = $this->getMimeType($secretKey); |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | $this->allowedMimetypes = $allowedMimetypes; |
35 | 35 | } |
36 | 36 | |
37 | - /** |
|
38 | - * $current_uri String actual uri of the file |
|
39 | - * $dest_folder String future uri of the file starting from web/upload folder |
|
40 | - * $lifetime DateTime lifetime of the file. If time goes over this limit, the file will be deleted. |
|
41 | - **/ |
|
42 | - public function upload(UploadedFile $file, $dest_folder = '', \DateTime $lifetime = null) |
|
43 | - { |
|
37 | + /** |
|
38 | + * $current_uri String actual uri of the file |
|
39 | + * $dest_folder String future uri of the file starting from web/upload folder |
|
40 | + * $lifetime DateTime lifetime of the file. If time goes over this limit, the file will be deleted. |
|
41 | + **/ |
|
42 | + public function upload(UploadedFile $file, $dest_folder = '', \DateTime $lifetime = null) |
|
43 | + { |
|
44 | 44 | |
45 | 45 | //Cleaning up old files before uploading this one |
46 | 46 | $this->cleanup(); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | $fs = new Filesystem(); |
65 | 65 | if (!$fs->exists($this->uploadDir.$dest_folder)) { |
66 | - $fs->mkdir($this->uploadDir.$dest_folder); |
|
66 | + $fs->mkdir($this->uploadDir.$dest_folder); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $em = $this->doctrine->getManager(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $em->flush(); |
118 | 118 | |
119 | 119 | return $media; |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | 122 | public function cleanup() |
123 | 123 | { |
@@ -32,15 +32,15 @@ discard block |
||
32 | 32 | $mediaPreview = $this->container->get('twig.extension.media_preview_extension'); |
33 | 33 | foreach ($this->get('request')->files as $files) { |
34 | 34 | if(!is_array($files)) |
35 | - $files = array($files); |
|
35 | + $files = array($files); |
|
36 | 36 | foreach($files as $file) { |
37 | - $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
|
38 | - $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
|
39 | - $returnData[] = array( |
|
40 | - 'id' => $media->getSecretKey(), |
|
41 | - 'path' => $path, |
|
42 | - 'name' => $media->getName(), |
|
43 | - ); |
|
37 | + $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
|
38 | + $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
|
39 | + $returnData[] = array( |
|
40 | + 'id' => $media->getSecretKey(), |
|
41 | + 'path' => $path, |
|
42 | + 'name' => $media->getName(), |
|
43 | + ); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
@@ -81,29 +81,29 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function showMediaAction(Media $media, $filter = null) |
83 | 83 | { |
84 | - $response = new Response(); |
|
84 | + $response = new Response(); |
|
85 | 85 | |
86 | - $lastModified = new \DateTime('now'); |
|
86 | + $lastModified = new \DateTime('now'); |
|
87 | 87 | |
88 | 88 | |
89 | - //Checking if it is an image or not |
|
90 | - $src = $this->get('media')->getAbsolutePath($media); |
|
91 | - $isImage = @getimagesize($src); |
|
89 | + //Checking if it is an image or not |
|
90 | + $src = $this->get('media')->getAbsolutePath($media); |
|
91 | + $isImage = @getimagesize($src); |
|
92 | 92 | |
93 | - if($isImage) { |
|
93 | + if($isImage) { |
|
94 | 94 | $response->headers->set('Content-disposition', 'inline;filename='.$media->getName()); |
95 | 95 | if (!empty($filter) && $isImage) { |
96 | 96 | |
97 | - $src = $this->get('media')->getAbsolutePath($media, $filter); |
|
98 | - $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
99 | - $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
97 | + $src = $this->get('media')->getAbsolutePath($media, $filter); |
|
98 | + $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
99 | + $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
100 | 100 | |
101 | - $uploadDir = $this->get('media')->getUploadDir($filter); |
|
101 | + $uploadDir = $this->get('media')->getUploadDir($filter); |
|
102 | 102 | |
103 | - if (!is_file($src)) { |
|
103 | + if (!is_file($src)) { |
|
104 | 104 | $fs = new Filesystem(); |
105 | 105 | if (!$fs->exists($uploadDir.$media->getFolder())) { |
106 | - $fs->mkdir($uploadDir.$media->getFolder()); |
|
106 | + $fs->mkdir($uploadDir.$media->getFolder()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $path = 'upload/'.$media->getUri(); |
@@ -111,33 +111,33 @@ discard block |
||
111 | 111 | $responseData = $filterManager->applyFilter($image, $filter); // run the filter |
112 | 112 | $data = $responseData->getContent(); // get the image from the response |
113 | 113 | file_put_contents($uploadDir.$media->getUri(), $data); |
114 | - } else { |
|
114 | + } else { |
|
115 | 115 | $data = file_get_contents($src); |
116 | 116 | $lastModified->setTimestamp(filemtime($src)); |
117 | - } |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } else { |
120 | - $src = $this->get('media')->getAbsolutePath($media); |
|
121 | - $lastModified->setTimestamp(filemtime($src)); |
|
122 | - $data = file_get_contents($src); |
|
120 | + $src = $this->get('media')->getAbsolutePath($media); |
|
121 | + $lastModified->setTimestamp(filemtime($src)); |
|
122 | + $data = file_get_contents($src); |
|
123 | 123 | } |
124 | - } else { |
|
124 | + } else { |
|
125 | 125 | $lastModified->setTimestamp(filemtime($src)); |
126 | 126 | $data = file_get_contents($src); |
127 | 127 | $response->headers->set('Content-disposition', 'attachment;filename='.basename($media->getUri())); |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | - $response->setLastModified($lastModified); |
|
131 | - $response->setPublic(); |
|
132 | - $response->headers->set('Content-Type', $media->getMime()); |
|
130 | + $response->setLastModified($lastModified); |
|
131 | + $response->setPublic(); |
|
132 | + $response->headers->set('Content-Type', $media->getMime()); |
|
133 | 133 | |
134 | - if ($response->isNotModified($this->get('request'))) { |
|
135 | - return $response; |
|
136 | - } |
|
134 | + if ($response->isNotModified($this->get('request'))) { |
|
135 | + return $response; |
|
136 | + } |
|
137 | 137 | |
138 | - $response->setContent($data); |
|
138 | + $response->setContent($data); |
|
139 | 139 | |
140 | - return $response; |
|
140 | + return $response; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | } |