@@ -131,7 +131,7 @@ private function getAllKeys($memcached): array {
131131 $ keys [] = [
132132 'key ' => $ key_data ['key ' ],
133133 'ttl ' => $ key_data ['exp ' ],
134- 'type ' => 'string ' , // In Memcache(d) everything is stored as string.
134+ 'type ' => 'string ' , // In Memcache(d) everything is stored as a string.
135135 ];
136136 }
137137
@@ -148,6 +148,10 @@ private function getAllKeys($memcached): array {
148148 private function mainDashboard ($ memcached ): string {
149149 $ keys = $ this ->getAllKeys ($ memcached );
150150
151+ if (isset ($ _POST ['submit_import_key ' ])) {
152+ $ this ->import ($ memcached );
153+ }
154+
151155 $ paginator = new Paginator ($ this ->template , $ keys );
152156
153157 return $ this ->template ->render ('dashboards/memcached/memcached ' , [
@@ -174,22 +178,51 @@ private function viewKey($memcached): string {
174178 Http::redirect ();
175179 }
176180
181+ if (isset ($ _GET ['export ' ])) {
182+ header ('Content-disposition: attachment; filename= ' .$ key .'.txt ' );
183+ header ('Content-Type: text/plain ' );
184+ echo $ memcached ->get ($ key );
185+ exit ;
186+ }
187+
177188 $ value = $ memcached ->get ($ key );
178189
179190 [$ value , $ encode_fn , $ is_formatted ] = Helpers::decodeAndFormatValue ($ value );
180191
181192 $ ttl = Http::get ('ttl ' , 'int ' );
182193
183194 return $ this ->template ->render ('partials/view_key ' , [
184- 'value ' => $ value ,
185- 'type ' => 'string ' , // In Memcache(d) everything is stored as string.
186- 'ttl ' => !empty ($ ttl ) ? Helpers::formatSeconds ($ ttl ) : null ,
187- 'encode_fn ' => $ encode_fn ,
188- 'formatted ' => $ is_formatted ,
189- 'edit_url ' => Http::queryString (['ttl ' ], ['form ' => 'edit ' , 'key ' => $ key ]),
195+ 'value ' => $ value ,
196+ 'type ' => 'string ' , // In Memcache(d) everything is stored as a string.
197+ 'ttl ' => !empty ($ ttl ) ? Helpers::formatSeconds ($ ttl ) : null ,
198+ 'encode_fn ' => $ encode_fn ,
199+ 'formatted ' => $ is_formatted ,
200+ 'edit_url ' => Http::queryString (['ttl ' ], ['form ' => 'edit ' , 'key ' => $ key ]),
201+ 'export_url ' => Http::queryString (['ttl ' , 'view ' , 'p ' , 'key ' ], ['export ' => 'key ' ]),
190202 ]);
191203 }
192204
205+ /**
206+ * Import key.
207+ *
208+ * @param Memcache|Memcached $memcached
209+ *
210+ * @return void
211+ */
212+ private function import ($ memcached ): void {
213+ if ($ _FILES ['import ' ]['type ' ] === 'text/plain ' ) {
214+ $ key_name = Http::post ('key_name ' );
215+
216+ if (empty ($ memcached ->get ($ key_name ))) {
217+ $ value = file_get_contents ($ _FILES ['import ' ]['tmp_name ' ]);
218+
219+ $ memcached ->store ($ key_name , $ value , Http::post ('expire ' , 'int ' ));
220+
221+ Http::redirect ();
222+ }
223+ }
224+ }
225+
193226 /**
194227 * Add/edit form.
195228 *
0 commit comments