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


PHP file_save_data函数代码示例

本文整理汇总了PHP中file_save_data函数的典型用法代码示例。如果您正苦于以下问题:PHP file_save_data函数的具体用法?PHP file_save_data怎么用?PHP file_save_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: file_upload

function file_upload($fileUrl, $file_path = "files")
{
    //echo $file_path;
    //	echo 's3://'.$fileUrl;
    $file_temp = file_get_contents('http://www.voteapps.com/' . $fileUrl);
    //print_r();
    //Saves a file to the specified destination and creates a database entry.
    if (!file_exists($public_path . '/apkfiles')) {
        drupal_mkdir($public_path . '/apkfiles');
    }
    $file_arry = file_save_data($file_temp, 's3://' . $fileUrl, FILE_EXISTS_REPLACE);
    //print_r($file_arry);
    //转存视频和图片
    if ($file_arry) {
        // echo "</br>上传成功...";
        return $file_arry;
    } else {
        //echo "</br>再次尝试上传...";
        $file_arry = file_save_data($file_temp, 's3://' . $fileUrl, FILE_EXISTS_REPLACE);
        if ($file_arry) {
            //清空视频
            //unlink($$fileUrl);
            //	echo "</br>上传成功...";
            return $file_arry;
        } else {
            //清空视频
            // unlink($$fileUrl);
            //	echo "</br>上传失败...";
            return $file_arry;
            //header('HTTP/1.1 500 Internal Server Error');
            //exit;
        }
    }
}
开发者ID:napoler,项目名称:t-drupal-module,代码行数:34,代码来源:appdl.php

示例2: testEmbedButtonIconUsage

 /**
  * Tests the embed_button and file usage integration.
  */
 public function testEmbedButtonIconUsage()
 {
     $this->enableModules(['system', 'user', 'file']);
     $this->installSchema('file', ['file_usage']);
     $this->installConfig(['system']);
     $this->installEntitySchema('user');
     $this->installEntitySchema('file');
     $this->installEntitySchema('embed_button');
     $file1 = file_save_data(file_get_contents('core/misc/druplicon.png'));
     $file1->setTemporary();
     $file1->save();
     $file2 = file_save_data(file_get_contents('core/misc/druplicon.png'));
     $file2->setTemporary();
     $file2->save();
     $button = array('id' => 'test_button', 'label' => 'Testing embed button instance', 'type_id' => 'embed_test_default', 'icon_uuid' => $file1->uuid());
     $entity = EmbedButton::create($button);
     $entity->save();
     $this->assertTrue(File::load($file1->id())->isPermanent());
     // Delete the icon from the button.
     $entity->icon_uuid = NULL;
     $entity->save();
     $this->assertTrue(File::load($file1->id())->isTemporary());
     $entity->icon_uuid = $file1->uuid();
     $entity->save();
     $this->assertTrue(File::load($file1->id())->isPermanent());
     $entity->icon_uuid = $file2->uuid();
     $entity->save();
     $this->assertTrue(File::load($file1->id())->isTemporary());
     $this->assertTrue(File::load($file2->id())->isPermanent());
     $entity->delete();
     $this->assertTrue(File::load($file2->id())->isTemporary());
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:35,代码来源:IconFileUsageTest.php

示例3: save

 function save(FileMaterial $fileMaterial)
 {
     $wo = wechat_api_init_wechatobj();
     $file_content = $wo->getForeverMedia($fileMaterial->media_id);
     $file = file_save_data($file_content, 'public://' . $fileMaterial->name);
     dpm($file);
 }
开发者ID:sosyuki,项目名称:wechat,代码行数:7,代码来源:FileMaterialSave.php

示例4: file_save_file

 public static function file_save_file($src, $dest)
 {
     $data = file_get_contents($src);
     $file = file_save_data($data, $dest, FILE_EXISTS_REPLACE);
     $fid = $file->id();
     return $fid;
 }
开发者ID:318io,项目名称:318-io,代码行数:7,代码来源:WG.php

示例5: sunshine_build_css_cache

function sunshine_build_css_cache($css_files)
{
    $data = '';
    // Create the css/ within the files folder.
    $csspath = file_create_path('css');
    $orgpath = drupal_get_path('theme', 'sunshine') . '/css/';
    file_check_directory($csspath, FILE_CREATE_DIRECTORY);
    // Build aggregate CSS file.
    foreach ($css_files as $key => $file) {
        $contents = drupal_load_stylesheet($orgpath . $file, TRUE);
        // Return the path to where this CSS file originated from.
        $base = base_path() . $orgpath;
        _drupal_build_css_path(NULL, $base);
        // Prefix all paths within this CSS file, ignoring external and absolute paths.
        $data .= preg_replace_callback('/url\\([\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\)/i', '_drupal_build_css_path', $contents);
    }
    // Per the W3C specification at http://www.w3.org/TR/REC-CSS2/cascade.html#at-import,
    // @import rules must proceed any other style, so we move those to the top.
    $regexp = '/@import[^;]+;/i';
    preg_match_all($regexp, $data, $matches);
    $data = preg_replace($regexp, '', $data);
    $data = implode('', $matches[0]) . $data;
    $checksum = md5($data);
    $filename_cache = 'sunshine.cache.css';
    // Create the CSS file.
    if (!file_exists($csspath . '/' . $filename_cache) || md5(file_get_contents($csspath . '/' . $filename_cache)) != $checksum) {
        // drupal_set_message('Sunshine CSS cache has been rebuilt.');
        file_save_data($data, $csspath . '/' . $filename_cache, FILE_EXISTS_REPLACE);
    }
    return $csspath . '/' . $filename_cache;
}
开发者ID:upei,项目名称:drupal6-cms,代码行数:31,代码来源:template.php

示例6: mylog

function mylog($data, $file_name)
{
    if (file_destination('public://log', FILE_EXISTS_ERROR)) {
        // The file doesn't exist. do something
        drupal_mkdir('public://log');
    }
    file_save_data(print_r($data, true), "public://log/{$file_name}", FILE_EXISTS_REPLACE);
}
开发者ID:318io,项目名称:318-io,代码行数:8,代码来源:easier.drupal.php

示例7: unhandleField

 public function unhandleField($entity_type, $field_type, $field_name, &$value)
 {
     if (!is_array($value)) {
         return;
     }
     if (!array_key_exists('url', $value)) {
         return;
     }
     if (!array_key_exists('original_path', $value)) {
         return;
     }
     if (!array_key_exists('uuid', $value)) {
         return;
     }
     if (!array_key_exists('uid', $value)) {
         return;
     }
     // Make sure a file doesn't already exist with that UUID.
     $entity = Entity::loadByUUID($value['uuid'], 'file');
     if ($entity) {
         $definition = $entity->definition;
     } else {
         // Make sure a file doesn't already exist with that URI.
         $query = db_select('file_managed', 'f');
         $query->addField('f', 'fid');
         $query->condition('f.uri', $value['original_path']);
         $query->range(0, 1);
         $result = $query->execute()->fetch();
         if ($result) {
             $entity = Entity::load($result->fid, 'file');
             if ($entity) {
                 $definition = $entity->definition;
             }
         }
     }
     // If we haven't found the file yet, upload it.
     if (!isset($definition)) {
         // Decode the contents of the file.
         $contents = file_get_contents($value['url']);
         if ($contents === false) {
             throw new FileHandlerException('There was an error fetching the contents of the file.');
         }
         // Save the file.
         $file = file_save_data($contents, $value['original_path']);
         if (!$file || !$file->fid) {
             throw new FileHandlerException('There was an error saving the file to the database.');
         }
         $file->uuid = $value['uuid'];
         $file->uid = $value['uid'];
         file_save($file);
         $definition = $file;
     }
     // Don't completely reset the entity.
     foreach ((array) $definition as $key => $val) {
         $this->unresolved_definition->{$key} = $val;
     }
 }
开发者ID:sammarks,项目名称:publisher,代码行数:57,代码来源:FileHandler.php

示例8: saveTranslationRequest

 /**
  * Helper method for saving requests coming to POETRY mock.
  *
  * @param string $message
  *    XML request.
  */
 public static function saveTranslationRequest($message, $reference)
 {
     $path = TMGMT_POETRY_MOCK_REQUESTS_PATH . $reference . '.xml';
     $dirname = dirname($path);
     if (file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
         file_save_data($message, $path);
     } else {
         watchdog('poetry_mock', 'Unable to prepare requests directory', array(), WATCHDOG_ERROR);
     }
 }
开发者ID:ec-europa,项目名称:platform-dev,代码行数:16,代码来源:PoetryMock.php

示例9: testAdvertiserImages

 /**
  *
  */
 public function testAdvertiserImages()
 {
     // Download an example image from the internet.
     $test_data = file_get_contents('https://www.drupal.org/sites/all/modules/drupalorg/drupalorg/images/qmark-400x684-2x.png');
     // Save the file to the temporary scheme, let's save it as a .txt so the validation fails...
     $image_file = file_save_data($test_data, 'temporary://test_test_test.txt', FILE_EXISTS_REPLACE);
     $image_file_uri = $image_file->getFileUri();
     // Create an entity and set the image file..
     $entity = Advertiser::create(['advertiser_image' => $image_file_uri]);
     $violations = $entity->validate();
     $this->assertEqual(count($violations), 1, 'Violation found when non-image filename.');
 }
开发者ID:gl2748,项目名称:advertiser_entity,代码行数:15,代码来源:AdvertiserValidationTest.php

示例10: _ad_blueprint_write_css

function _ad_blueprint_write_css()
{
    // Set the location of the custom.css file
    $file_path = file_directory_path() . '/ad_blueprint/custom.css';
    // If the directory doesn't exist, create it
    file_check_directory(dirname($file_path), FILE_CREATE_DIRECTORY);
    // Generate the CSS
    $file_contents = _ad_blueprint_build_css();
    $output = '<div class="description">' . t('This CSS is generated by the settings chosen above and placed in the files directory: ' . l($file_path, $file_path) . '. The file is generated each time this page (and only this page) is loaded. <strong class="marker">Make sure to refresh your page to see the changes</strong>') . '</div>';
    file_save_data($file_contents, $file_path, FILE_EXISTS_REPLACE);
    return $output;
}
开发者ID:hoangbktech,项目名称:bhl-bits,代码行数:12,代码来源:theme-settings.php

示例11: requestTranslation

 /**
  * {@inheritdoc}
  */
 public function requestTranslation(JobInterface $job)
 {
     $name = "JobID" . $job->id() . '_' . $job->getSourceLangcode() . '_' . $job->getTargetLangcode();
     $export = \Drupal::service('plugin.manager.tmgmt_file.format')->createInstance($job->getSetting('export_format'));
     $path = $job->getSetting('scheme') . '://tmgmt_file/' . $name . '.' . $job->getSetting('export_format');
     $dirname = dirname($path);
     if (file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
         $file = file_save_data($export->export($job), $path);
         \Drupal::service('file.usage')->add($file, 'tmgmt_file', 'tmgmt_job', $job->id());
         $job->submitted('Exported file can be downloaded <a href="@link">here</a>.', array('@link' => file_create_url($path)));
     }
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:15,代码来源:FileTranslator.php

示例12: run

 /**
  * Called when this activity gets activated and run by the containing
  * ConductorWorkflow's controller.
  */
 public function run()
 {
     $state = $this->getState();
     $mobile = $state->getContext('sms_number');
     // Mobile Commons sends the international code in its payload. Remove it.
     $mobile = substr($mobile, -10);
     // Get user by mobile number if it exists. Otherwise create it.
     $user = dosomething_user_get_user_by_mobile($mobile);
     if (!$user) {
         $user = dosomething_user_create_user_by_mobile($mobile);
     }
     // Initialize reportback values, defaulting to create a new reportback.
     $values = array('rbid' => 0);
     // Check for a previously submitted reportback to update instead.
     if ($rbid = dosomething_reportback_exists($this->nid, $user->uid)) {
         $values['rbid'] = $rbid;
     }
     // Get the MMS URL from the provided context.
     $pictureUrl = $state->getContext($this->mmsContext);
     // Get the location for where file should be saved to.
     $fileDest = dosomething_reportback_get_file_dest(basename($pictureUrl), $this->nid, $user->uid);
     // Download and save file to that location.
     $pictureContents = file_get_contents($pictureUrl);
     $file = file_save_data($pictureContents, $fileDest);
     // Save UID and permanent status.
     $file->uid = $user->uid;
     $file->status = FILE_STATUS_PERMANENT;
     file_save($file);
     // Get the fid to submit with the report back.
     $values['fid'] = $file->fid;
     // Get answers from context and set them to their appropriate properties.
     foreach ($this->propertyToContextMap as $property => $context) {
         $values[$property] = $state->getContext($context);
     }
     // Set nid and uid.
     $values['nid'] = $this->nid;
     $values['uid'] = $user->uid;
     // Create/update a report back submission.
     $rbid = dosomething_reportback_save($values);
     // Update user's profile if this is the first completed campaign.
     $updateArgs = array();
     if (empty($_REQUEST['profile_first_completed_campaign_id']) && !empty($this->mobileCommonsCompletedCampaignId)) {
         $updateArgs['person[first_completed_campaign_id]'] = $this->mobileCommonsCompletedCampaignId;
     }
     // Opt the user out of the main campaign.
     if (!empty($this->optOutCampaignId)) {
         dosomething_sms_mobilecommons_opt_out($mobile, $this->optOutCampaignId);
     }
     // Opt user into a path to send the confirmation message.
     dosomething_sms_mobilecommons_opt_in($mobile, $this->optInPathId, $updateArgs);
     $state->setContext('ignore_no_response_error', TRUE);
     $state->markCompleted();
 }
开发者ID:sergii-tkachenko,项目名称:phoenix,代码行数:57,代码来源:ConductorActivitySmsReportBack.class.php

示例13: expand

 /**
  * {@inheritdoc}
  */
 public function expand($values)
 {
     $data = file_get_contents($values[0]);
     if (FALSE === $data) {
         throw new \Exception("Error reading file");
     }
     /* @var \Drupal\file\FileInterface $file */
     $file = file_save_data($data, 'public://' . uniqid() . '.jpg');
     if (FALSE === $file) {
         throw new \Exception("Error saving file");
     }
     $file->save();
     $return = array('target_id' => $file->id(), 'alt' => 'Behat test image', 'title' => 'Behat test image');
     return $return;
 }
开发者ID:shrimala,项目名称:DrupalDriver,代码行数:18,代码来源:ImageHandler.php

示例14: createTemporaryFile

 /**
  * Creates a temporary file, for a specific user.
  *
  * @param string $data
  *   A string containing the contents of the file.
  * @param \Drupal\user\UserInterface $user
  *   The user of the file owner.
  *
  * @return \Drupal\file\FileInterface
  *   A file object, or FALSE on error.
  */
 protected function createTemporaryFile($data, UserInterface $user = NULL)
 {
     $file = file_save_data($data, NULL, NULL);
     if ($file) {
         if ($user) {
             $file->setOwner($user);
         } else {
             $file->setOwner($this->adminUser);
         }
         // Change the file status to be temporary.
         $file->setTemporary();
         // Save the changes.
         $file->save();
     }
     return $file;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:27,代码来源:FileFieldWidgetTest.php

示例15: process

 /**
  * Parse attachments from message mimeparts.
  */
 function process(&$message, $source)
 {
     $message['attachments'] = array();
     foreach ($message['mimeparts'] as $attachment) {
         // 'unnamed_attachment' files are not really attachments, but mimeparts like HTML or Plain Text.
         // We only want to save real attachments, like images and files.
         if ($attachment->filename !== 'unnamed_attachment') {
             $destination = 'temporary://';
             $filename = mb_decode_mimeheader($attachment->filename);
             $file = file_save_data($attachment->data, $destination . $filename);
             $file->status = 0;
             drupal_write_record('file_managed', $file, 'fid');
             $message['attachments'][] = new FeedsEnclosure($file->uri, $attachment->filemime);
         }
     }
     unset($message['mimeparts']);
 }
开发者ID:tierce,项目名称:ppbe,代码行数:20,代码来源:MailhandlerCommandsFiles.class.php


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