本文整理汇总了PHP中file_save函数的典型用法代码示例。如果您正苦于以下问题:PHP file_save函数的具体用法?PHP file_save怎么用?PHP file_save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_save函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _os_files_deprivatize_file
/**
* Moves a private managed file to the public directory.
*/
function _os_files_deprivatize_file($fid)
{
$file = file_load($fid);
// Builds new public path.
$dest_uri = str_replace('private://', 'public://', $file->uri);
$dest_path = _os_files_deprivatize_get_dest_path($dest_uri);
// Creates the destination folder if it doesn't exist.
if (!is_dir($dest_path)) {
// Creates the folder.
drupal_mkdir($dest_path, NULL, TRUE);
}
$moved_file = @file_move($file, $dest_uri);
if ($moved_file) {
drush_log(dt('File @name moved successfully.', array('@name' => $file->filename)), 'success');
} else {
drush_log(dt('Error moving file @name.', array('@name' => $file->filename)), 'error');
return FALSE;
}
$file->uri = $moved_file->uri;
$file_moved = file_save($file);
if (isset($file_moved->fid)) {
drush_log(dt('[O] File @name updated successfully.', array('@name' => $file->filename)), 'success');
return TRUE;
} else {
drush_log(dt('[!] Error updating file @name.', array('@name' => $file->filename)), 'error');
return FALSE;
}
}
开发者ID:aleph-n,项目名称:opencholar,代码行数:31,代码来源:deprivatize.php
示例2: parse
public function parse(ServicesContextInterface $context) {
global $user;
$destination = DATASET_FILE_STORAGE_DESTINATION;
if (substr($destination, -1) != '/') {
$destination .= '/';
}
$file = new stdClass();
$file->uid = $user->uid;
$file->status = 0;
$file->filename = uniqid('push-api_');
$file->uri = file_destination($destination . $file->filename, FILE_EXISTS_RENAME);
$file->filemime = 'text/csv';
if ( false === file_put_contents($file->uri,$context->getRequestBody()) ) {
throw new IllegalArgumentException(t('Could not store received data on file system'));
}
drupal_chmod($file->uri);
file_save($file);
return array(PARAMETER_NAME_CONTENT => $file);
}
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:25,代码来源:gd_dataset_uploader_source_rest.php
示例3: addPicture
function addPicture($FID, $moduleName)
{
$f = file_load($FID);
$f->status = FILE_STATUS_PERMANENT;
file_save($f);
addUsage($f, $moduleName);
// tells Drupal we're using the file
}
开发者ID:ChapResearch,项目名称:CROMA,代码行数:8,代码来源:pictureFunctions.php
示例4: 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
示例5: addFile
private static function addFile($imageFileId, $moduleName, $fieldName)
{
/* if our file is already in use, then we don't need to re-do this and increase the count */
$count = db_query('SELECT `count` FROM {file_usage} WHERE fid=:fid', array('fid' => $imageFileId))->fetchField();
$file = file_load($imageFileId);
if (empty($count)) {
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, $moduleName, $fieldName, $imageFileId);
}
return $file;
}
开发者ID:poupouxios,项目名称:drupal-resume,代码行数:12,代码来源:ImageHelper.php
示例6: 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
示例7: az_commercial_settings_form_submit
function az_commercial_settings_form_submit(&$form, $form_state)
{
$image_fid = $form_state['values']['main_background'];
$image = file_load($image_fid);
if (is_object($image)) {
if ($image->status == 0) {
$image->status = FILE_STATUS_PERMANENT;
file_save($image);
file_usage_add($image, 'az_gov', 'theme', 1);
}
}
}
开发者ID:ehazell,项目名称:AZDWR,代码行数:12,代码来源:theme-settings.php
示例8: daycare_background_validate
/**
* implements ddaycare_background_validate
*/
function daycare_background_validate($element, &$form_state)
{
global $base_url;
$validators = array('file_validate_is_image' => array());
$file = file_save_upload('background', $validators, "public://", FILE_EXISTS_REPLACE);
if ($file) {
// change file's status from temporary to permanent and update file database
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
$file_url = file_create_url($file->uri);
$file_url = str_ireplace($base_url . '/', '', $file_url);
// set to form
$form_state['values']['bg_file'] = $file_url;
}
}
开发者ID:puridi,项目名称:Hotel,代码行数:18,代码来源:theme-settings.php
示例9: puzzle_settings_form_submit
function puzzle_settings_form_submit(&$form, &$form_state)
{
$image_fid = $form_state['values']['background_image'];
$image = file_load($image_fid);
if (is_object($image)) {
// Check to make sure that the file is set to be permanent.
if ($image->status == 0) {
// Update the status.
$image->status = FILE_STATUS_PERMANENT;
// Save the update.
file_save($image);
// Add a reference to prevent warnings.
file_usage_add($image, 'puzzle', 'theme', 1);
}
}
}
开发者ID:Koreychenko,项目名称:puzzle,代码行数:16,代码来源:template.php
示例10: sizzle_form_system_theme_settings_submit
/**
* Submit handler for system_theme_settings().
*/
function sizzle_form_system_theme_settings_submit($form, &$form_state)
{
$values = $form_state['values'];
// Save images.
foreach ($values as $name => $value) {
if (preg_match('/_image$/', $name)) {
if (!empty($values[$name])) {
$file = file_load($values[$name]);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, 'sizzle', 'theme', 1);
variable_set($name, $file->fid);
}
}
}
}
开发者ID:shinjanidhar,项目名称:book-your-show,代码行数:19,代码来源:theme-settings.php
示例11: brafton_admin_form_submit
function brafton_admin_form_submit($form, &$form_state)
{
//reset the error report
if ($form_state['values']['brafton_clear_report']) {
variable_set('brafton_e_log', '');
//variable_set('brafton_clear_report', 0);
}
//runs importer if archive is loaded
//Handles background image for videos
if ($form_state['values']['brafton_video_end_cta_background'] != '') {
$file = file_load($form_state['values']['brafton_video_end_cta_background']);
// Change status to permanent.
$file->status = FILE_STATUS_PERMANENT;
// Save.
$newfile = file_save($file);
$name = basename('brafton.module', '.module');
file_usage_add($newfile, $name, $name, $newfile->fid);
variable_set('brafton_video_end_cta_background_url', $newfile->uri);
variable_set('brafton_video_end_cta_background_id', $newfile->fid);
} else {
if (!$form_state['values']['brafton_video_end_cta_background']['fid']) {
variable_set('brafton_video_end_cta_background_url', '');
variable_del('brafton_video_end_cta_background_id');
}
}
//Handles Button Image for videos
if ($form_state['values']['brafton_video_end_cta_button_image'] != '') {
$file = file_load($form_state['values']['brafton_video_end_cta_button_image']);
// Change status to permanent.
$file->status = FILE_STATUS_PERMANENT;
// Save.
$newfile = file_save($file);
$name = basename('brafton.module', '.module');
file_usage_add($newfile, $name, $name, $newfile->fid);
variable_set('brafton_video_end_cta_button_image_url', $newfile->uri);
variable_set('brafton_video_end_cta_button_image_id', $newfile->fid);
} else {
if (!$form_state['values']['brafton_video_end_cta_button_image']['fid']) {
variable_set('brafton_video_end_cta_button_image_url', '');
variable_del('brafton_video_end_cta_button_image_id');
}
}
//Ensure that the run manual imports
$form_state['values']['brafton_clear_report'] = 0;
}
开发者ID:ContentLEAD,项目名称:BraftonDrupal7Module,代码行数:45,代码来源:braftonAdmin.php
示例12: parallax_bg_region5_validate
function parallax_bg_region5_validate($element, &$form_state)
{
global $base_url;
$validateFile = array('file_validate_is_image' => array());
$UploadedFile = file_save_upload('parallax_bg_region5_image', $validateFile, "public://", FILE_EXISTS_REPLACE);
if ($form_state['values']['delete_parallax_bg_region5_image'] == TRUE) {
file_unmanaged_delete($form_state['values']['parallax_bg_region5_preview']);
$form_state['values']['parallax_bg_region5_preview'] = NULL;
}
if ($UploadedFile) {
$UploadedFile->status = FILE_STATUS_PERMANENT;
file_save($UploadedFile);
$file_url = file_create_url($UploadedFile->uri);
$file_url = str_ireplace($base_url, '', $file_url);
// set to form
$form_state['values']['parallax_bg_region5_preview'] = $file_url;
}
}
开发者ID:ApsGitAdmin,项目名称:APS,代码行数:18,代码来源:parallax-image-validate.php
示例13: logger
/**
* Logs with an arbitrary level.
*
* @param string $level
* @param string $message
* @param array $context
*
* @return void
*/
function logger(string $level, string $message, array $context = []) : void
{
if (empty($context['file'])) {
$context['file'] = 'qnd.log';
}
$file = path('log', $context['file']);
file_save($file, '[' . $level . '][' . date('r') . '] ' . $message . "\n\n", FILE_APPEND);
}
开发者ID:akilli,项目名称:qnd,代码行数:17,代码来源:logger.php
示例14: _platon_store_css_override_file
/**
* Helper function to write the CSS override file.
*
* If a file already existed, the old one is set to a temporary file so Drupal cleans it up. Returns the new file fid.
*
* @param string $content
*
* @return int
*/
function _platon_store_css_override_file($content)
{
global $user;
// If a file already existed, set it to a temporary file so
// Drupal cleans it up.
if ($file = _platon_get_css_override_file()) {
$file->status = 0;
file_save($file);
}
if (empty($content)) {
return 0;
}
// Create a new file.
$filename = uniqid(md5($content)) . '_platon_override.css';
$uri = "public://{$filename}";
$f = fopen($uri, 'w');
// If the write succeeds, store it as a managed file.
if (fwrite($f, $content)) {
fclose($f);
$file = (object) array('uri' => $uri, 'filename' => $filename, 'status' => FILE_STATUS_PERMANENT, 'uid' => $user->uid);
file_save($file);
// Return the file id.
return $file->fid;
} else {
// The write didn't succeed. Return 0.
return 0;
}
}
开发者ID:xin07crc,项目名称:iluminacionesmap,代码行数:37,代码来源:template.php
示例15: entity_save
/**
* Implement the save function for the entity.
*/
public function entity_save($entity)
{
file_save($entity);
}
开发者ID:GitError404,项目名称:favrskov.dk,代码行数:7,代码来源:PanelizerEntityFile.class.php
示例16: array
echo "<br />";
$msg = array();
function file_save($filename, $content, $flags = 0)
{
if (!($file = fopen($filename, 'w'))) {
return FALSE;
}
$n = fwrite($file, $content);
fclose($file);
return $n ? $n : FALSE;
}
if (!file_exists("chat.php")) {
file_save("chat.php", "<?php\n\$msg = " . var_export($msg, TRUE) . "\n?>");
}
include "chat.php";
while (count($msg) >= 100) {
array_shift($msg);
}
$msg2 = array_reverse($msg);
echo "<div align='center' class='chat'><table width='92%'>";
include INCL_PATH . 'offset.php';
for ($i = 0; $i < count($msg2); ++$i) {
echo "<tr><td class='header' align='left'>" . security::html_safe($msg2[$i]['pseudo']) . " [" . date("d/m/y H:i:s", $msg2[$i]['date'] - $offset) . "]</td></tr><tr><td class='lista' align='left'>" . format_shout($msg2[$i]['texte']) . "</td></tr>";
}
echo "</table></div>";
file_save("chat.php", "<?php\n\$msg = " . var_export($msg, TRUE) . "\n?>");
print "<br />";
block_end();
print "<br />";
print "<div align='center'><a href='javascript: window.close()'>" . CLOSE . "</a></div>";
stdfoot(false);
开发者ID:HDVinnie,项目名称:BtiTracker-1.5.0,代码行数:31,代码来源:allshout.php
示例17: form_file
<?php
require_once 'includes/header.inc.php';
require_once 'includes/uploads.inc.php';
function form_file()
{
form_dump(array('file' => array('file', 'file'), 'submit' => array('submit', 'Save post')), 'enctype="multipart/form-data"');
}
if (!isset($_POST['submit']) || empty($_POST['submit'])) {
echo 'Please select the file to upload:<br />';
} else {
if ($fname = file_save($_FILES['file'])) {
echo 'file saved under <file><a href="/forum/uploads/' . $fname . '"></file>' . $fname . "</a><br />\n<br />\n";
} else {
echo 'failed to save file';
}
echo '<br />' . "\n";
}
form_file();
echo '<br /><br />' . "\n";
require_once 'includes/footer.inc.php';
开发者ID:vulnerabilityCode,项目名称:ctf,代码行数:21,代码来源:uploads.php
示例18: site_bg_validate
function site_bg_validate($element, &$form_state)
{
global $base_url;
$validateFile = array('file_validate_is_image' => array());
$UploadedFile = file_save_upload('site_bg_image', $validateFile, "public://", FILE_EXISTS_REPLACE);
if ($form_state['values']['delete_site_bg_image'] == TRUE) {
// Delete layer file
file_unmanaged_delete($form_state['values']['site_bg_preview']);
$form_state['values']['site_bg_preview'] = NULL;
}
if ($UploadedFile) {
// change file's status from temporary to permanent and update file database
$UploadedFile->status = FILE_STATUS_PERMANENT;
file_save($UploadedFile);
$file_url = file_create_url($UploadedFile->uri);
$file_url = str_ireplace($base_url, '', $file_url);
// set to form
$form_state['values']['site_bg_preview'] = $file_url;
}
}
开发者ID:vfokov,项目名称:videosite,代码行数:20,代码来源:theme-settings.php
示例19: platon_form_system_theme_settings_alter_validate
/**
* Validation callback for platon_form_system_theme_settings_alter().
*/
function platon_form_system_theme_settings_alter_validate($form, &$form_state)
{
if (!empty($_FILES['files']['name']['platon_header_image_upload'])) {
$file = file_save_upload('platon_header_image_upload', array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')), 'public://');
if ($file) {
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
$form_state['storage']['header_file'] = $file;
} else {
form_set_error('platon_header_image_upload', t("Couldn't upload file."));
}
}
if (!empty($_FILES['files']['name']['platon_home_page_image_upload'])) {
$file = file_save_upload('platon_home_page_image_upload', array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')), 'public://');
if ($file) {
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
$form_state['storage']['home_file'] = $file;
} else {
form_set_error('platon_home_page_image_upload', t("Couldn't upload file."));
}
}
if (!empty($form_state['values']['platon_css_override_content'])) {
if ($fid = _platon_store_css_override_file($form_state['values']['platon_css_override_content'])) {
$form_state['storage']['css_fid'] = $fid;
} else {
form_set_error('platon_css_override_content', t("Could not save the CSS in a file. Perhaps the server has no write access. Check your public files folder permissions."));
}
}
}
开发者ID:sirusdas,项目名称:opigno,代码行数:33,代码来源:theme-settings.php
示例20: saveFile
/**
* Save uploaded file. Call this from the form submit handler
* @return
* true if success, false if not
* @param object $file_field[optional]
* field name of the form
* @param object $file_type[optional]
* acceptable MIME type substring, e.g. 'image/'
*/
function saveFile($file_field = 'attachment', $file_type = '')
{
if (isset($_FILES[$file_field]) && !empty($_FILES[$file_field]['name'])) {
// we only care about single file uploads here
$uploadkey = '';
//the original name of the file is $_FILES[$file_field]['name'][$upload_key]
if (is_array($_FILES[$file_field]['name'])) {
foreach ($_FILES[$file_field]['name'] as $key => $val) {
$uploadkey = $key;
break;
}
}
// valid attachment ?
if ($file_type != '') {
if (!eregi($file_type, $uploadkey == '' ? $_FILES[$file_field]['type'] : $_FILES[$file_field]['type'][$uploadkey])) {
// invalid data mime type found
return false;
}
}
//01. we store the file into the file_managed table temporarily, and get the file object
$file = file_save_upload($uploadkey, array(), NULL);
//02. we get the file id in the file_managed table, and by using the file id together with the original filename, we create the new filename
//also, we store the file id into the last_upload_id
$filename = $file->fid . $_FILES[$file_field]['name'][$uploadkey];
$this->last_uploaded_id = $file->fid;
//03. we save the file to be uploaded into the public file directory.
$file = file_move($file, 'public://' . $filename, FILE_EXISTS_REPLACE);
//04. set file the status to be permanently and save the file.
$file->status = FILE_STATUS_PERMANENT;
variable_set('file_id', $file->fid);
file_save($file);
//upload success;
return true;
} else {
// invalid attachment data found
return false;
}
}
开发者ID:zevergreenz,项目名称:Drupal,代码行数:47,代码来源:cvwobase_d7_fileupload.php
注:本文中的file_save函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论