Esempio n. 1
0
 public function updateImage(Request $request)
 {
     $return['ok'] = 0;
     $id = $request->input('tagId');
     $imageName = $request->input('name');
     try {
         $tagService = new tagService();
         $return['data'] = $tagService->updateImage($id, $imageName);
         $return['ok'] = 1;
     } catch (Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = TR::l('EDITOR/MESSAGE/ERROR/SHARE_BIN');
         $return['errorMsg'] = $e->getMessage();
         Binumi_Util::logErr($e->getMessage());
         // @codeCoverageIgnoreEnd
     }
     return response()->json($return);
 }
Esempio n. 2
0
 /**
  * Upload controller, chunk action
  *
  * @access public
  */
 public function chunk(Request $request)
 {
     $chunk = (int) $request->input('chunk', 0);
     $chunks = (int) $request->input('chunks', 0);
     $isVoice = $request->input('voice');
     if ($isVoice) {
         $fileName = $request->input('Filename', '');
         $fileKey = 'recording';
     } else {
         $fileName = $request->input('name', '');
         $fileKey = 'file';
     }
     $ext = pathinfo($fileName, PATHINFO_EXTENSION);
     $fileName = 'kacana__product_' . md5($fileName);
     $return = array('ok' => 0, 'jsonrpc' => '2.0', 'message' => '', 'id' => 'id', 'name' => '');
     try {
         $contentType = $this->getContentType();
         $targetDir = PRODUCT_IMAGE;
         $filePath = $targetDir . $fileName;
         $finalFileName = $fileName . '.' . $ext;
         $partFilePath = $filePath . '.' . 'part';
         $finalFilePath = $filePath . '.' . $ext;
         $this->cleanUploadDir($targetDir, $partFilePath);
         $this->setExecutionTime();
         $this->setHeaders();
         // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
         if (strpos($contentType, "multipart") !== false) {
             if (isset($_FILES[$fileKey]['tmp_name']) && is_uploaded_file($_FILES[$fileKey]['tmp_name'])) {
                 // Open temp file
                 $out = fopen($partFilePath, $chunk == 0 ? "wb" : "ab");
                 if ($out) {
                     // Read binary input stream and append it to temp file
                     $in = fopen($_FILES[$fileKey]['tmp_name'], "rb");
                     if ($in) {
                         while ($buff = fread($in, 4096)) {
                             fwrite($out, $buff);
                         }
                     } else {
                         throw new Exception('Failed to open input stream');
                     }
                     fclose($in);
                     fclose($out);
                     @unlink($_FILES[$fileKey]['tmp_name']);
                 } else {
                     throw new Exception('Failed to open output stream');
                 }
             } else {
                 throw new Exception('Failed to move uploaded file');
             }
         } else {
             // Open temp file
             $out = fopen($partFilePath, $chunk == 0 ? "wb" : "ab");
             if ($out) {
                 // Read binary input stream and append it to temp file
                 $in = fopen("php://input", "rb");
                 if ($in) {
                     while ($buff = fread($in, 4096)) {
                         fwrite($out, $buff);
                     }
                 } else {
                     throw new Exception('Failed to open input stream');
                 }
                 fclose($in);
                 fclose($out);
             } else {
                 throw new Exception('Failed to open output stream');
             }
         }
         if (!$chunks || $chunk == $chunks - 1) {
             $type = $request->input('type');
             $isOverlay = false;
             if ($type == 'overlay') {
                 $isOverlay = true;
             }
             // Strip the temp .part suffix off
             rename($partFilePath, $finalFilePath);
             $return['name'] = '/' . $filePath . '.' . $ext;
             $return['ok'] = 1;
         }
     } catch (Exception $e) {
         // @codeCoverageIgnoreStart
         Binumi_Util::logErr($e->getMessage());
         $return['message'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
     return response()->json($return);
 }