Esempio n. 1
0
 public function executeUpload(sfWebRequest $request)
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
         $errormessage = 'The server was unable to handle that much POST data (' . $_SERVER['CONTENT_LENGTH'] . ' bytes) due to its current configuration : ' . ini_get('post_max_size');
         // return $this->jsonError($request, $errormessage);
         return $this->renderPartial('search/error', array('error_message' => $errormessage));
     }
     $this->formfileupload = new FileUploadForm();
     if ($request->isMethod('post')) {
         $this->formfileupload->bind($request->getParameter('fileupload'), $request->getFiles('fileupload'));
         if ($this->formfileupload->isValid()) {
             $file = $this->formfileupload->getValue('mp3');
             $fileInfo = smintUploadFileHelper::saveFile($file);
             # possibly add generate waveform code HERE ???
             return $this->renderPartial('search/fileupload', array('fileInfo' => $fileInfo, 'metadataquery' => $this->formfileupload->getValue('metadataquery')));
         } else {
             // if form validation failed
             $form_errors = array("Form error" => "following errors while validating form:");
             foreach ($this->formfileupload->getFormFieldSchema() as $name => $formField) {
                 if ($formField->hasError()) {
                     $current_error = $formField->getName() . ' - ' . (string) $formField->getError();
                     $form_errors[] = $current_error;
                 }
             }
             if ($this->formfileupload->hasGlobalErrors()) {
                 foreach ($this->formfileupload->getGlobalErrors() as $validator_error) {
                     $form_errors[] = $validator_error->getMessage();
                 }
             }
             return $this->renderPartial('search/error', array('error_message' => $form_errors));
         }
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize default context
     sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('smint', 'dev', true));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     $tmpFilePath = smintUploadFileHelper::getUploadPath();
     $tmpfname = tempnam($tmpFilePath, "uploadscript.tmp");
     copy($options['filename'], $tmpfname);
     $newFile = new sfValidatedFile($options['filename'], "audio/mpeg", $tmpfname, null, $tmpFilePath);
     $fileInfo = smintUploadFileHelper::saveFile($newFile);
     //print_r($fileInfo);
     echo "originalFilename=" . urlencode($fileInfo["originalFilename"]) . "&existingUploadedFile=" . urlencode($fileInfo["filename"]) . "\n";
     unlink($tmpfname);
 }