Пример #1
0
 function bUseUploadedImageFile(&$oFromPath, &$oOrgFilename)
 {
     global $goApp;
     $sNewFilename = "";
     $sExt = $oOrgFilename->sExtension();
     if ($oFromPath) {
         $oFromFile = new WYFile($oFromPath);
         $oToPath = od_clone($goApp->oDataPath);
         $sNewFilename = $this->sDataFileName(true) . "-" . mt_rand(1000, 9999) . "." . $sExt;
         $oToPath->addComponent($sNewFilename);
         if ($oFromFile->bMoveTo($oToPath)) {
             $this->deleteImage();
             // delete old image
             chmod($oToPath->sPath, 0644);
             list($iOW, $iOH) = WYImage::aGetImageSize($oToPath);
             if ($this->iImageWidth != 0 || $this->iImageHeight != 0) {
                 // image dimensions set?
                 list($iCW, $iCH) = $this->aContrainedSize($iOW, $iOH, false);
                 // constrained image size
                 if ($iCW != $iOW || $iCH != $iOH) {
                     $oResizedPath = od_clone($oToPath);
                     if (!WYImage::bResizeImage($oToPath, $oResizedPath, $iCW, $iCH)) {
                         $goApp->log("resizing failed for: " . $oToPath->sPath);
                     }
                 }
             }
             if ($this->bIsThumb) {
                 list($iCW, $iCH) = $this->aContrainedSize($iOW, $iOH, true);
                 // constrained size for thumbnail
                 $this->deleteThumbnail();
                 $oResizedPath = $this->oThumbnailPathFor($oToPath);
                 $this->dContent[WY_DK_THUMBNAIL_FILENAME] = $oResizedPath->sBasename();
                 if (!WYImage::bResizeImage($oToPath, $oResizedPath, $iCW, $iCH)) {
                     $goApp->log("resizing failed for: " . $oToPath->sPath . ", " . $oResizedPath->sPath);
                     $this->deleteThumbnail();
                 }
             }
             $this->dContent[WY_DK_IMAGEFILENAME] = $sNewFilename;
             return true;
         } else {
             $goApp->log("could not move image file: " . $oFromPath->sPath . " to " . $oToPath->sPath);
             return false;
         }
     }
 }
Пример #2
0
 function useUploadedFile(&$oFromPath, &$oOrgFilename)
 {
     global $goApp;
     $sFN = "";
     if ($oFromPath) {
         $oFromFile = new WYFile($oFromPath);
         $this->deleteFile();
         $this->setOriginalFilename($oOrgFilename->sPath);
         $sFN = $this->sDownloadFileName();
         $oToPath = od_clone($goApp->oDataPath);
         $oToPath->addComponent($sFN);
         if (!$oFromFile->bMoveTo($oToPath)) {
             $goApp->log("could not move attachment file: " . $oFromPath->sPath . " to " . $oToPath->sPath);
             $this->deleteFile();
             $this->setOriginalFilename("");
         } else {
             chmod($oToPath->sPath, 0644);
         }
     }
 }
Пример #3
0
 /**
  * Bereitet ein hochgeladenes Bild für die Verwendung durch WebYep vor
  *
  * Folgende Aktionen werden durchgeführt:
  * - es wird ein Name der Form /webyep-system/dat(a|en)/{Document-ID}-{Number}-gl-{Name}-{RND(1000-9999)}.ext vergeben
  * - prüfen, ob das Bild evtl. zu groß ist und ggf. verkleinern
  * - Vorschaubild erstellen
  * - Dateiberechtigungen setzen
  * - temporäre Dateien löschen
  *
  *	@param		object		&$oFromPath		temporärer Dateiname (/tmp/filename4711 vom Webserver vergeben)
  *	@param		object		&$oOrgFilename	Originalname der Datei vor dem Upload
  *	@param		int			$iID				imageID, welche dem Bild zugewiesen werden soll
  */
 function useUploadedImageFileForID(&$oFromPath, &$oOrgFilename, $iID)
 {
     global $goApp;
     $sNewFilename = "";
     $sExt = strtolower($oOrgFilename->sExtension());
     $aItems =& $this->_aItems();
     $dItem = array();
     $bSuccess = false;
     if ($oFromPath && isset($aItems[$iID])) {
         $oFromFile = new WYFile($oFromPath);
         $oToPath = od_clone($goApp->oDataPath);
         $sNewFilename = $this->sDataFileName(true) . "-" . mt_rand(1000, 9999) . "." . $sExt;
         $oToPath->addComponent($sNewFilename);
         $bOK = false;
         $a = WYImage::aGetImageSize($oFromPath);
         $iW = $a[0];
         $iH = $a[1];
         if (!WYImage::bLimitSize($iW, $iH, $this->iImageWidth, $this->iImageHeight)) {
             if ($oFromFile->bMoveTo($oToPath)) {
                 $bOK = true;
             } else {
                 $goApp->log("WYGallery: could not move image file: " . $oFromPath->sPath . " to " . $oToPath->sPath);
             }
         } else {
             $oTMPPath = od_clone($goApp->oDataPath);
             $oTMPPath->addComponent("WYGalleryUpload_" . mt_rand(1000, 9999) . "." . $sExt);
             if ($oFromFile->bMoveTo($oTMPPath)) {
                 if (WYImage::bResizeImage($oTMPPath, $oToPath, $iW, $iH)) {
                     $bOK = true;
                 } else {
                     $goApp->log("WYGallery: could not resize uploaded image file: " . $oFromPath->sPath);
                 }
                 if (!@unlink($oTMPPath->sPath)) {
                     $goApp->log("WYGallery: could not unlink uploaded image file: " . $oTMPPath->sPath);
                 }
             } else {
                 $goApp->log("WYGallery: could not move image file: " . $oFromPath->sPath . " to " . $oTMPPath->sPath);
             }
         }
         if ($bOK) {
             $this->_deleteImageFilesForID($iID);
             $dItem =& $aItems[$iID];
             $dItem[WY_DK_GALLERY_FILENAME] = $sNewFilename;
             chmod($oToPath->sPath, 0644);
             if (!$this->_bCreateThumbNailFor($sNewFilename)) {
                 $oTNPath = od_clone($oToPath);
                 $oTNPath->removeLastComponent();
                 $oTNPath->addComponent($this->_sThumbnailName($sNewFilename));
                 $oTNPath->setExtension($oToPath->sExtension());
                 $oFile = new WYFile($oToPath);
                 if (!$oFile->bCopyTo($oTNPath)) {
                     $goApp->log("could not copy image {$sNewFilename} to thumbnail");
                 } else {
                     chmod($oTNPath->sPath, 0644);
                 }
             }
         }
     }
 }