📄 storage.php.svn-base
字号:
} // need to update the size and date in the db. $this->controller->File->id = $_upload['File']['id']; $this->controller->File->saveField('size',filesize($_filename)); break; case 'microsummary/xml': $ms = new microsummary(); $ms->load($_upload['Contentsource']['source']); $rv = $ms->execute($_upload['Upload']['referrer'], true); if ($rv == 2) { // The XPATH has been updated based on the // hint passed. Lets save this new content // source to the database $updated_source = $ms->save(); // save in db: $this->controller->Contentsource->id = $_upload['Contentsource']['id']; $this->controller->Contentsource->saveField('source', $updated_source); } if (empty($ms->result)) { $ms->result = "XPATH is broken.. this feature doesn't work for the content you have selected. "; $this->log("Microsummary ". $_upload['Contentsource']['id'] . "does not have an xpath result"); } // does the user have enough space to proceed if ($this->controller->Storage->hasAvailableSpace($_owner['User']['id'], strlen($ms->result) - filesize($_filename)) == false) { $this->log("User " . $_owner['User']['id'] . " is out of space."); return false; } // write the file. if (!file_put_contents($_filename, $ms->result)) { $this->log("file_put_contents failed for " . $_filename); return false; } // need to update the size and date in the db. $this->controller->File->id = $_upload['File']['id']; $this->controller->File->saveField('size',filesize($_filename)); break; case 'widget/joey': $jw = new joeywidget(); $jw->load($_upload['Contentsource']['source']); //@todo check for available space // write the file. if (!file_put_contents($_filename, $jw->content)) { $this->log("file_put_contents failed for " . $_filename); return false; } if (!file_put_contents($_previewname, $jw->preview)) { $this->log("file_put_contents failed for " . $_previewname); return false; } // need to update the size and date in the db. $this->controller->File->id = $_upload['File']['id']; $this->controller->File->saveField('size',filesize($_filename)); $this->controller->File->saveField('preview_size',filesize($_filename)); break; // We don't support whatever they're trying to update. :( default: return false; } } // If we've made it this far without failing, we're good return true; } /* * Transcode the input image to PNG and then generate a preview PNG. * The file type is implied in the file name suffix. */ function transcodeImage ($fromName, $toName, $previewName, $width, $height) { $_fromName = escapeshellarg($fromName); $_toName = escapeshellarg($toName); $_previewName = escapeshellarg($previewName); $_cmd = CONVERT_CMD." -geometry '{$width}x{$height}' {$_fromName} {$_toName}"; exec($_cmd, $_out, $_ret); if ($_ret !== 0) { $this->log("transcodeImage failed: " . $_cmd); return false; } // @todo why 1/2? $width = intval($width / 2); $height = intval($height / 2); $_cmd = CONVERT_CMD." -geometry '{$width}x{$height}' {$_toName} {$_previewName}"; exec($_cmd, $_out, $_ret); if ($_ret !== 0) { $this->log("transcodeImage failed: " . $_cmd); return false; } return true; } /* * Transcode the input video to 3GP and then generate a preview PNG. * The file type is implied in the file name suffix */ function transcodeVideo ($fromName, $toName, $previewName, $width, $height) { $_fromName = escapeshellarg($fromName); $_toName = escapeshellarg($toName); $_previewName = escapeshellarg($previewName); $_cmd = FFMPEG_CMD . " -y -i {$_fromName} -ab 32 -b 15000 -ac 1 -ar 8000 -vcodec h263 -s qcif -r 12 {$_toName}"; exec($_cmd, $_out, $_ret); if ($_ret !== 0) { $this->log("transcodeVideo failed: " . $_cmd); return false; } $width = intval($width / 2); $height = intval($height / 2); $_cmd = FFMPEG_CMD . " -i {$_fromName} -ss 5 -s '{$width}x{$height}' -vframes 1 -f mjpeg {$_previewName}"; exec($_cmd, $_out, $_ret); if ($_ret !== 0) { $this->log("transcodeVideo failed: " . $_cmd); return false; } return true; } function processUpload($tmpfilename, $userid, $type, $width, $height) { if (!is_numeric($userid)) { return null; } if (!is_dir(UPLOAD_DIR."/{$userid}")) { return null; } if (!array_key_exists($type, $this->suffix)) { return null; } $_ret = array ('default_name' => '', 'default_type' => '', 'original_name' => '', 'original_type' => '', 'preview_name' => '', 'preview_type' => ''); $rand = uniqid(); if (strcasecmp($type, 'video/flv') == 0) { $_ret['original_name'] = UPLOAD_DIR."/{$userid}/originals/"."joey-".$rand.".".$this->suffix[$type]; $_ret['original_type'] = $type; $_ret['default_name'] = UPLOAD_DIR."/{$userid}/"."joey-".$rand.".3gp"; $_ret['default_type'] = "video/3gpp"; $_ret['preview_name'] = UPLOAD_DIR."/{$userid}/previews/"."joey-".$rand.".png"; $_ret['preview_type'] = "image/png"; if (!move_uploaded_file($tmpfilename, $_ret['original_name'])) { return null; } if (!$this->transcodeVideo($_ret['original_name'], $_ret['default_name'], $_ret['preview_name'], $width, $height)) { return null; } return $_ret; } else if (strcasecmp($type, 'image/png') == 0 || strcasecmp($type, 'image/jpeg') == 0 || strcasecmp($type, 'image/tiff') == 0 || strcasecmp($type, 'image/bmp') == 0 || strcasecmp($type, 'image/gif') == 0) { $_ret['original_name'] = UPLOAD_DIR."/{$userid}/originals/"."joey-".$rand.".".$this->suffix[$type]; $_ret['original_type'] = $type; $_ret['default_name'] = UPLOAD_DIR."/{$userid}/"."joey-".$rand.".png"; $_ret['default_type'] = "image/png"; $_ret['preview_name'] = UPLOAD_DIR."/{$userid}/previews/"."joey-".$rand.".png"; $_ret['preview_type'] = "image/png"; if (!move_uploaded_file($tmpfilename, $_ret['original_name'])) { return null; } if (!$this->transcodeImage($_ret['original_name'], $_ret['default_name'], $_ret['preview_name'], $width, $height)) { return null; } return $_ret; } else { $_ret['default_name'] = UPLOAD_DIR."/{$userid}/"."joey-".$rand.".".$this->suffix[$type]; $_ret['default_type'] = $type; if (!move_uploaded_file($tmpfilename, $_ret['default_name'])) { return null; } return $_ret; } }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -