Пример #1
0
 public function acceptsURL($sUrl, $bCreateType = false)
 {
     $sFileName = substr($sUrl, strrpos($sUrl, '/') + 1);
     $aName = explode('.', $sFileName);
     $sExtension = null;
     if (count($aName) > 1) {
         $sExtension = array_pop($aName);
     }
     $sFileName = implode('.', $aName);
     $aHeaders = @get_headers($sUrl, true);
     $sMimeType = null;
     $oDocumentType = null;
     if ($aHeaders && isset($aHeaders['Content-Type'])) {
         $sMimeType = $aHeaders['Content-Type'];
         $oDocumentType = DocumentTypeQuery::findDocumentTypeByMimetype($sMimeType);
     }
     if ($oDocumentType === null && $sExtension !== null) {
         $oDocumentType = DocumentTypePeer::getDocumentTypeByExtension($sExtension);
     }
     if ($oDocumentType === null && $bCreateType && $sMimeType && $sExtension) {
         $oDocumentType = new DocumentType();
         $oDocumentType->setExtension($sExtension);
         $oDocumentType->setMimetype($sMimeType);
         $oDocumentType->save();
     }
     if ($oDocumentType === null) {
         throw new LocalizedException("wns.file_upload.document_type_not_found", array('extension' => $sExtension, 'mimetype' => $sMimeType));
     }
     return $oDocumentType->getId();
 }