当前位置: 首页>>代码示例>>PHP>>正文


PHP Upload::getFile方法代码示例

本文整理汇总了PHP中Upload::getFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::getFile方法的具体用法?PHP Upload::getFile怎么用?PHP Upload::getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Upload的用法示例。


在下文中一共展示了Upload::getFile方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if (!isset($_FILES[$this->name])) {
         return false;
     }
     $fileClass = File::get_class_for_file_extension(pathinfo($_FILES[$this->name]['name'], PATHINFO_EXTENSION));
     if ($this->relationAutoSetting) {
         // assume that the file is connected via a has-one
         $hasOnes = $record->has_one($this->name);
         // try to create a file matching the relation
         $file = is_string($hasOnes) ? Object::create($hasOnes) : new $fileClass();
     } else {
         $file = new $fileClass();
     }
     $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->folderName);
     if ($this->upload->isError()) {
         return false;
     }
     $file = $this->upload->getFile();
     if ($this->relationAutoSetting) {
         if (!$hasOnes) {
             return false;
         }
         // save to record
         $record->{$this->name . 'ID'} = $file->ID;
     }
     return $this;
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:28,代码来源:FileField.php

示例2: saveInto

 public function saveInto(DataObject $record)
 {
     if (!isset($_FILES[$this->name])) {
         return false;
     }
     if ($this->relationAutoSetting) {
         // assume that the file is connected via a has-one
         $hasOnes = $record->has_one($this->name);
         // try to create a file matching the relation
         $file = is_string($hasOnes) ? Object::create($hasOnes) : new File();
     } else {
         $file = new File();
     }
     $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->folderName);
     if ($this->upload->isError()) {
         return false;
     }
     $file = $this->upload->getFile();
     if ($this->relationAutoSetting) {
         if (!$hasOnes) {
             return false;
         }
         // save to record
         $record->{$this->name . 'ID'} = $file->ID;
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:26,代码来源:FileField.php

示例3: doUpload

 function doUpload($data, $form)
 {
     if (isset($data['UploadedMedia']['tmp_name'])) {
         if (!empty($data['UploadedMedia']['name'])) {
             // create new single file array from file uploads array
             $file = array();
             $file['name'] = $data['UploadedMedia']['name'];
             $file['type'] = $data['UploadedMedia']['type'];
             $file['tmp_name'] = $data['UploadedMedia']['tmp_name'];
             $file['error'] = $data['UploadedMedia']['error'];
             $file['size'] = $data['UploadedMedia']['size'];
             // create & write uploaded file in DB
             try {
                 $newfile = new File();
                 $upload = new Upload();
                 // get folder from form upload field
                 $folder = $form->Fields()->fieldByName('UploadedMedia')->getFolderName();
                 $upload->loadIntoFile($file, $newfile, $folder);
                 $fileObj = $upload->getFile();
                 $EventID = Session::get('UploadMedia.PresentationID');
                 if ($EventID) {
                     $Event = VideoPresentation::get()->byID($EventID);
                 }
                 if (isset($Event)) {
                     $Event->UploadedMediaID = $fileObj->ID;
                     $Event->MediaType = 'File';
                     $Event->write();
                     Session::set('UploadMedia.Success', TRUE);
                     Session::set('UploadMedia.FileName', $fileObj->Name);
                     Session::set('UploadMedia.Type', 'File');
                     Controller::curr()->redirect($form->controller()->link() . 'Success');
                 }
             } catch (ValidationException $e) {
                 $form->sessionMessage('Extension not allowed...', 'bad');
                 return $this->controller()->redirectBack();
             }
         }
     }
 }
开发者ID:Thingee,项目名称:openstack-org,代码行数:39,代码来源:PresentationMediaUploadForm.php

示例4: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if (!isset($_FILES[$this->name])) {
         return false;
     }
     $fileClass = File::get_class_for_file_extension(File::get_file_extension($_FILES[$this->name]['name'], PATHINFO_EXTENSION));
     if ($this->relationAutoSetting) {
         // assume that the file is connected via a has-one
         $objectClass = $record->hasOne($this->name);
         if ($objectClass === 'File' || empty($objectClass)) {
             // Create object of the appropriate file class
             $file = Object::create($fileClass);
         } else {
             // try to create a file matching the relation
             $file = Object::create($objectClass);
         }
     } else {
         if ($record instanceof File) {
             $file = $record;
         } else {
             $file = Object::create($fileClass);
         }
     }
     $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->getFolderName());
     if ($this->upload->isError()) {
         return false;
     }
     if ($this->relationAutoSetting) {
         if (!$objectClass) {
             return false;
         }
         $file = $this->upload->getFile();
         $record->{$this->name . 'ID'} = $file->ID;
     }
     return $this;
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:36,代码来源:FileField.php

示例5: testFileVersioningWithAnExistingFile

 public function testFileVersioningWithAnExistingFile()
 {
     $upload = function ($tmpFileName) {
         // create tmp file
         $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
         $tmpFileContent = '';
         for ($i = 0; $i < 10000; $i++) {
             $tmpFileContent .= '0';
         }
         file_put_contents($tmpFilePath, $tmpFileContent);
         // emulates the $_FILES array
         $tmpFile = array('name' => $tmpFileName, 'type' => 'text/plaintext', 'size' => filesize($tmpFilePath), 'tmp_name' => $tmpFilePath, 'extension' => 'jpg', 'error' => UPLOAD_ERR_OK);
         $v = new UploadTest_Validator();
         // test upload into default folder
         $u = new Upload();
         $u->setReplaceFile(false);
         $u->setValidator($v);
         $u->loadIntoFile($tmpFile);
         return $u->getFile();
     };
     // test empty file version prefix
     Config::inst()->update('SilverStripe\\Filesystem\\Storage\\DefaultAssetNameGenerator', 'version_prefix', '');
     $file1 = $upload('UploadTest-IMG001.jpg');
     $this->assertEquals('UploadTest-IMG001.jpg', $file1->Name, 'File does not receive new name');
     $file2 = $upload('UploadTest-IMG001.jpg');
     $this->assertEquals('UploadTest-IMG002.jpg', $file2->Name, 'File does receive new name');
     $file3 = $upload('UploadTest-IMG002.jpg');
     $this->assertEquals('UploadTest-IMG003.jpg', $file3->Name, 'File does receive new name');
     $file4 = $upload('UploadTest-IMG3.jpg');
     $this->assertEquals('UploadTest-IMG3.jpg', $file4->Name, 'File does not receive new name');
     $file1->delete();
     $file2->delete();
     $file3->delete();
     $file4->delete();
     // test '-v' file version prefix
     Config::inst()->update('SilverStripe\\Filesystem\\Storage\\DefaultAssetNameGenerator', 'version_prefix', '-v');
     $file1 = $upload('UploadTest2-IMG001.jpg');
     $this->assertEquals('UploadTest2-IMG001.jpg', $file1->Name, 'File does not receive new name');
     $file2 = $upload('UploadTest2-IMG001.jpg');
     $this->assertEquals('UploadTest2-IMG001-v2.jpg', $file2->Name, 'File does receive new name');
     $file3 = $upload('UploadTest2-IMG001.jpg');
     $this->assertEquals('UploadTest2-IMG001-v3.jpg', $file3->Name, 'File does receive new name');
     $file4 = $upload('UploadTest2-IMG001-v3.jpg');
     $this->assertEquals('UploadTest2-IMG001-v4.jpg', $file4->Name, 'File does receive new name');
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:45,代码来源:UploadTest.php

示例6: testFileVersioningWithAnExistingFile

 public function testFileVersioningWithAnExistingFile()
 {
     $upload = function ($tmpFileName) {
         // create tmp file
         $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
         $tmpFileContent = '';
         for ($i = 0; $i < 10000; $i++) {
             $tmpFileContent .= '0';
         }
         file_put_contents($tmpFilePath, $tmpFileContent);
         // emulates the $_FILES array
         $tmpFile = array('name' => $tmpFileName, 'type' => 'text/plaintext', 'size' => filesize($tmpFilePath), 'tmp_name' => $tmpFilePath, 'extension' => 'jpg', 'error' => UPLOAD_ERR_OK);
         $v = new UploadTest_Validator();
         // test upload into default folder
         $u = new Upload();
         $u->setReplaceFile(false);
         $u->setValidator($v);
         $u->load($tmpFile);
         return $u->getFile();
     };
     $file1 = $upload('UploadTest-testUpload.jpg');
     $this->assertEquals('UploadTest-testUpload.jpg', $file1->Name, 'File does not receive new name');
     $file2 = $upload('UploadTest-testUpload.jpg');
     $this->assertEquals('UploadTest-testUpload2.jpg', $file2->Name, 'File does receive new name');
     $file3 = $upload('UploadTest-testUpload.jpg');
     $this->assertEquals('UploadTest-testUpload3.jpg', $file3->Name, 'File does receive new name');
     $file4 = $upload('UploadTest-testUpload3.jpg');
     $this->assertEquals('UploadTest-testUpload4.jpg', $file4->Name, 'File does receive new name');
     $file1->delete();
     $file2->delete();
     $file3->delete();
     $file4->delete();
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:33,代码来源:UploadTest.php

示例7: imageupload

 public function imageupload()
 {
     if (!Member::currentUserID()) {
         $return = array('error' => 1, 'text' => "Cannot upload there");
         return Convert::raw2json($return);
     }
     if (isset($_FILES['NewImage']) && ($tempfile = $_FILES['NewImage'])) {
         // validate //
         $allowed = array('jpg', 'jpeg', 'gif', 'png', 'ico');
         $nameBits = explode('.', $tempfile['name']);
         $ext = end($nameBits);
         if (!in_array(strtolower($ext), $allowed)) {
             $return = array('error' => 1, 'text' => "Your image must be in jpg, gif or png format");
             return Convert::raw2json($return);
         }
         $maxsize = $_POST['MAX_FILE_SIZE'];
         if ($tempfile['size'] > $maxsize) {
             $size = number_format($maxsize / 1024 / 1024, 2) . 'MB';
             $return = array('error' => 1, 'text' => "Your image must be smaller than {$size}");
             return Convert::raw2json($return);
         }
         // upload //
         $upload = new Upload();
         $file = new Image();
         $upload->loadIntoFile($tempfile, $file);
         if ($upload->isError()) {
             return false;
         }
         $file = $upload->getFile();
         $return = array('link' => $file->Link());
         return Convert::raw2json($return);
     } else {
         // no file to upload
         return false;
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-simplewiki,代码行数:36,代码来源:WikiPage.php

示例8: buildScreenshots

 private function buildScreenshots(Addon $addon, PackageInterface $package, $path)
 {
     $extra = $package->getExtra();
     $screenshots = array();
     $target = self::SCREENSHOTS_DIR . '/' . $addon->Name;
     if (isset($extra['screenshots'])) {
         $screenshots = (array) $extra['screenshots'];
     } elseif (isset($extra['screenshot'])) {
         $screenshots = (array) $extra['screenshot'];
     }
     // Delete existing screenshots.
     foreach ($addon->Screenshots() as $screenshot) {
         $screenshot->delete();
     }
     $addon->Screenshots()->removeAll();
     foreach ($screenshots as $screenshot) {
         if (!is_string($screenshot)) {
             continue;
         }
         $scheme = parse_url($screenshot, PHP_URL_SCHEME);
         // Handle absolute image URLs.
         if ($scheme == 'http' || $scheme == 'https') {
             $temp = TEMP_FOLDER . '/' . md5($screenshot);
             if (!copy($screenshot, $temp)) {
                 continue;
             }
             $data = array('name' => basename($screenshot), 'size' => filesize($temp), 'tmp_name' => $temp, 'error' => 0);
         } else {
             $source = $path . '/' . ltrim($screenshot, '/');
             // Prevent directory traversal.
             if ($source != realpath($source)) {
                 continue;
             }
             if (!file_exists($source)) {
                 continue;
             }
             $data = array('name' => basename($source), 'size' => filesize($source), 'tmp_name' => $source, 'error' => 0);
         }
         $upload = new Upload();
         $upload->setValidator(new AddonBuilderScreenshotValidator());
         $upload->load($data, $target);
         if ($file = $upload->getFile()) {
             $addon->Screenshots()->add($file);
         }
     }
 }
开发者ID:newleeland,项目名称:addons.silverstripe.org,代码行数:46,代码来源:AddonBuilder.php

示例9: testDeleteResampledImagesOnUpload

 public function testDeleteResampledImagesOnUpload()
 {
     $tmpFileName = 'UploadTest-testUpload.jpg';
     $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
     $uploadImage = function () use($tmpFileName, $tmpFilePath) {
         copy(__DIR__ . '/gdtest/test_jpg.jpg', $tmpFilePath);
         // emulates the $_FILES array
         $tmpFile = array('name' => $tmpFileName, 'type' => 'text/plaintext', 'size' => filesize($tmpFilePath), 'tmp_name' => $tmpFilePath, 'extension' => 'jpg', 'error' => UPLOAD_ERR_OK);
         $v = new UploadTest_Validator();
         // test upload into default folder
         $u = new Upload();
         $u->setReplaceFile(true);
         $u->setValidator($v);
         $u->load($tmpFile);
         return $u->getFile();
     };
     // Image upload and generate a resampled image
     $image = $uploadImage();
     $resampled = $image->ResizedImage(123, 456);
     $resampledPath = $resampled->getFullPath();
     $this->assertTrue(file_exists($resampledPath));
     // Re-upload the image, overwriting the original
     // Resampled images should removed when their parent file is overwritten
     $image = $uploadImage();
     $this->assertFalse(file_exists($resampledPath));
     unlink($tmpFilePath);
     $image->delete();
 }
开发者ID:fanggu,项目名称:loveyourwater_ss_v3.1.6,代码行数:28,代码来源:UploadTest.php

示例10: getFile

 /**
  *
  * @param type $key
  * @return boolean
  * @throws Exception
  */
 public static function getFile($key)
 {
     return Upload::getFile($key);
 }
开发者ID:hugoofab,项目名称:XLibrary,代码行数:10,代码来源:Request.php

示例11: saveappletupload

 public function saveappletupload($request)
 {
     $location = (int) $request->postVar('Location');
     if ($location) {
         $folder = DataObject::get_by_id('Folder', $location);
         if (isset($_FILES) && isset($_FILES['screenshot'])) {
             $upload = new Upload();
             if ($upload->load($_FILES['screenshot'], substr($folder->Filename, 7))) {
                 // need to base64decode the file data
                 $data = file_get_contents($upload->getFile()->getFullPath());
                 file_put_contents($upload->getFile()->getFullPath(), base64_decode($data));
                 $upload->getFile()->ClassName = 'Image';
                 $upload->getFile()->write();
                 return '{"file": ' . Convert::raw2json($upload->getFile()->toMap()) . '}';
             }
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-pixlr,代码行数:18,代码来源:PixlrController.php

示例12: header

        $sRender = $pGeshi->parse_code();
        file_put_contents($sCacheItem, $sRender);
    } else {
        $sRender = file_get_contents($sCacheItem);
    }
    header("Cache-Control: public");
    header("Last-Modified: " . date("r", filemtime($sCacheItem)));
    header("Content-Length: " . filesize($sCacheItem));
    header("Content-Type: text/html");
    header("Content-Transfer-Encoding: binary");
    header("Content-MD5: " . md5_file($sCacheItem));
    header("Content-Disposition: inline; filename=" . $pFunctions->quote($pUpload->file_name));
    echo $sRender;
} else {
    header("Cache-Control: public");
    header("Last-Modified: " . date("r", filemtime($pUpload->local_path)));
    header("Content-Length: {$pUpload->file_size}");
    header("Content-Type: {$pUpload->mime_type}");
    header("Content-Transfer-Encoding: binary");
    header("Content-MD5: {$pUpload->file_hash}");
    header("Content-Disposition: inline; filename=" . $pFunctions->quote($pUpload->file_name));
    $rPointer = $pUpload->getFile();
    $sContents = "";
    while ($sContents = fread($rPointer, 1024)) {
        echo $sContents;
        flush();
    }
    fclose($rPointer);
}
$pUpload->incrementViews();
return;
开发者ID:jannispl,项目名称:phpuush,代码行数:31,代码来源:file-handler.php


注:本文中的Upload::getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。