Exemplo n.º 1
0
 /**
  * moves uploaded temp file to permanent save location
  * @param string bean_id ID of parent bean
  * @return bool True on success
  */
 function final_move($bean_id)
 {
     $destination = $bean_id;
     if (substr($destination, 0, 9) != "upload://") {
         $destination = "upload://{$bean_id}";
     }
     if ($this->use_soap) {
         if (!file_put_contents($destination, $this->file)) {
             $GLOBALS['log']->fatal("ERROR: can't save file to {$destination}");
             return false;
         }
     } else {
         if (!UploadStream::move_uploaded_file($_FILES[$this->field_name]['tmp_name'], $destination)) {
             $GLOBALS['log']->fatal("ERROR: can't move_uploaded_file to {$destination}. You should try making the directory writable by the webserver");
             return false;
         }
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * moves uploaded temp file to permanent save location
  * @param string $bean_id ID of parent bean
  * @param boolean $temporary set true to move the file to temp folder
  * @return bool True on success
  */
 function final_move($bean_id, $temporary = false)
 {
     $destination = $bean_id;
     if (substr($destination, 0, 9) != "upload://") {
         $destination = "upload://{$bean_id}";
     }
     if ($temporary === true) {
         $tempFolder = "upload://tmp/";
         if (!is_dir($tempFolder)) {
             sugar_mkdir($tempFolder, 0755, true);
         }
         $destination = $tempFolder . $bean_id;
     }
     if ($this->use_soap) {
         if (!file_put_contents($destination, $this->file)) {
             $this->setError('fatal', "ERROR: can't save file to {$destination}");
             return false;
         }
     } else {
         if (!UploadStream::move_uploaded_file($_FILES[$this->field_name]['tmp_name'], $destination)) {
             if (isset($_FILES[$this->field_name]['_SUGAR_API_UPLOAD']) && $_FILES[$this->field_name]['_SUGAR_API_UPLOAD'] === true) {
                 // Try to move it manually
                 if (copy($_FILES[$this->field_name]['tmp_name'], $destination)) {
                     unlink($_FILES[$this->field_name]['tmp_name']);
                 } else {
                     $this->setError('fatal', "ERROR: can't move_uploaded_file to {$destination}. You should try making the directory writable by the webserver");
                     return false;
                 }
             } else {
                 $this->setError('fatal', "ERROR: can't move_uploaded_file to {$destination}. You should try making the directory writable by the webserver");
                 return false;
             }
         }
     }
     return true;
 }