You are here

private function Uploader::savefileToDrupal in UEditor - 百度编辑器 7.2

Same name and namespace in other branches
  1. 7.3 includes/Uploader.class.inc \Uploader::savefileToDrupal()

上传保存文件到drupal

Parameters

$imagedata:

$savePath:

Return value

string

3 calls to Uploader::savefileToDrupal()
Uploader::saveRemote in includes/Uploader.class.inc
拉取远程图片
Uploader::upBase64 in includes/Uploader.class.inc
处理base64编码的图片上传
Uploader::upFile in includes/Uploader.class.inc
上传文件的主处理方法

File

includes/Uploader.class.inc, line 287

Class

Uploader
Created by JetBrains PhpStorm. User: taoqili Date: 12-7-18 Time: 上午11: 32 UEditor编辑器通用上传类

Code

private function savefileToDrupal($imagedata, $savePath) {
  global $user;
  $filedata = '';

  //save the file to file_managed table.
  if ($uri = file_unmanaged_save_data($imagedata, 'public://' . $savePath, FILE_EXISTS_REPLACE)) {

    // Create a file object.
    $file = new stdClass();
    $file->fid = NULL;
    $file->uri = $uri;
    $file->filename = drupal_basename($uri);
    $file->filemime = file_get_mimetype($file->uri);
    $file->uid = $user->uid;
    $file->status = 0;
    $existing_files = file_load_multiple(array(), array(
      'uri' => $uri,
    ));
    if (count($existing_files)) {
      $existing = reset($existing_files);
      $file->fid = $existing->fid;
      $file->filename = $existing->filename;
    }
    $filedata = file_save($file);
  }
  return $filedata;
}