本文整理匯總了PHP中file::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP file::create方法的具體用法?PHP file::create怎麽用?PHP file::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類file
的用法示例。
在下文中一共展示了file::create方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveDesign
public function saveDesign()
{
$results = array();
// check user login
$user = $this->session->userdata('user');
if (empty($user['id'])) {
$results['error'] = 1;
$results['login'] = 1;
$results['msg'] = lang('design_msg_save_login');
echo json_encode($results);
exit;
}
$data = json_decode(file_get_contents('php://input'), true);
$this->load->helper('file');
$path = ROOTPATH . DS . 'media' . DS . 'assets' . DS . 'system';
$temp = explode(';base64,', $data['image']);
$buffer = base64_decode($temp[1]);
$design = array();
$design['user_id'] = $user['id'];
$design['vectors'] = $data['vectors'];
$design['teams'] = $data['teams'];
$design['fonts'] = $data['fonts'];
$designer_id = $data['designer_id'];
// check design and author
if ($data['design_file'] != '' && $designer_id == $design['user_id']) {
// override file and update
$file = $data['design_file'];
$path_file = ROOTPATH . DS . str_replace('/', DS, $file);
$id = $data['design_id'];
$key = $data['design_key'];
} else {
// save new file
$this->load->library('file');
$file = new file();
// create path file
$date = new DateTime();
$year = $date->format('Y');
$file->create($path . DS . $year, 0755);
$month = $date->format('m');
$file->create($path . DS . $year . DS . $month, 0755);
$key = strtotime("now") . rand();
$file = $key . '.png';
$path_file = $path . DS . $year . DS . $month . DS . $file;
$file = 'media/assets/system/' . $year . '/' . $month . '/' . $file;
$id = null;
$design['design_id'] = $key;
}
if (!write_file($path_file, $buffer)) {
$results['error'] = 1;
$results['msg'] = lang('design_msg_save');
} else {
$design['image'] = $file;
$design['product_id'] = $data['product_id'];
$design['product_options'] = $data['product_color'];
$design['title'] = '';
$design['description'] = '';
$design['system_id'] = '';
$this->load->model('design_m');
$id = $this->design_m->save($design, $id);
if ($id > 0) {
$results['error'] = 0;
$content = array('design_id' => $id, 'design_key' => $key, 'designer_id' => $user['id'], 'design_file' => $file);
$results['content'] = $content;
// send email savedesign.
//params shortcode email.
$params = array('username' => $user['username'], 'url_design' => site_url('design/index/' . $data['product_id'] . '/' . $data['product_color'] . '/' . $key));
//config email.
$config = array('mailtype' => 'html');
$subject = configEmail('sub_save_design', $params);
$message = configEmail('save_design', $params);
$this->load->library('email', $config);
$this->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
$this->email->to($user['email']);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
} else {
$results['error'] = 1;
$results['msg'] = lang('design_msg_save');
}
}
echo json_encode($results);
}
示例2: createFile
function createFile($data, $prefix = '', $filename = '', $file_url = '')
{
$path = ROOTPATH . DS . 'media' . DS . 'assets' . DS . 'system';
$CI = get_instance();
if ($file_url == '') {
$CI->load->library('file');
$file = new file();
$date = new DateTime();
$year = $date->format('Y');
$file->create($path . DS . $year, 0755);
$month = $date->format('m');
$file->create($path . DS . $year . DS . $month, 0755);
if ($filename == '') {
$file = $prefix . '_' . strtotime("now") . '.png';
} else {
$file = $prefix . '_' . $filename . '.png';
}
$path_file = $path . DS . $year . DS . $month . DS . $file;
$file = 'media/assets/system/' . $year . '/' . $month . '/' . $file;
} else {
$path_file = $path . DS . str_replace('/', DS, $file_url);
}
$temp = explode(';base64,', $data);
$buffer = base64_decode($temp[1]);
$CI->load->helper('file');
if (!write_file($path_file, $buffer)) {
return '';
} else {
return $file;
}
}
示例3: add
function add()
{
$path = $this->input->post('path');
$folder = $this->input->post('folder');
$this->load->library('file');
$file = new file();
$path = $this->root . DS . $path . DS . $folder;
$check = $file->create($path, 0755);
if ($check == false) {
echo lang('media_exists');
} else {
echo 1;
}
exit;
}