我在上传文件时遇到问题,当我将图像上传到网站时,看到此错误:
严重性:通知
消息:遇到格式不正确的数值
文件名:libraries / Upload.php
行号:1088
回溯:
文件:C:\ xampp \ htdocs \ code \ application \ controllers \ Register.php行: 50功能:do_upload
文件:C:\ xampp \ htdocs \ code \ index.php行:315功能:require_once
但是图片已成功上传并添加到我的数据库中!所以为什么我看到这个错误?
这是我控制器的整个代码:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Register extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model("register_model");
$this->load->model("user_model");
}
public function index()
{
// recaptcha begin
$this->load->library('Recaptcha');
$recaptcha = $this->input->post('g-recaptcha-response');
if (!empty($recaptcha)) {
$response = $this->recaptcha->verifyResponse($recaptcha);
if (isset($response['success']) and $response['success'] === true) {
echo "success !";
}
}
//end off recaptcha
//begin of upload script
//Check whether user upload picture
if(!empty($_FILES['picture']['name'])){
$config['upload_path'] = 'uploads/images/';
$config['allowed_types'] = 'jpg|jpeg|png';
$config['file_name'] = $_FILES['picture']['name'];
$config['encrypt_name'] = TRUE;
$config['overwrite'] = FALSE;
$config['max_filename'] = 300;
$config['remove_spaces'] = TRUE;
$config['max_size'] = 2000;
$config['xss_clean'] = TRUE;
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('picture')){
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
}else{
$picture = '';
}
}else{
$picture = '';
}
//end of upload script
if ($this->user_model->check_block_ip()) {
$this->template->error(lang("error_26"));
}
$this->template->set_error_view("error/login_error.php");
$this->template->set_layout("layout/login_layout.php");
if ($this->settings->info->register) {
$this->template->error(lang("error_54"));
}
$this->template->loadExternal(
'<script type="text/javascript" src="'
.base_url().'scripts/custom/check_username.js" /></script>'
);
if ($this->user->loggedin) {
$this->template->error(
lang("error_27")
);
}
$this->load->helper('email');
$email = "";
$name = "";
$username = "";
$fail = "";
$first_name = "";
$last_name = "";
$phone = "";
$city = "";
$address = "";
$jobs = "";
$education = "";
$diplome = "";
$worktime = "";
$freeservices = "";
if (isset($_POST['s'])) {
$email = $this->input->post("email", true);
$first_name = $this->common->nohtml(
$this->input->post("first_name", true));
$last_name = $this->common->nohtml(
$this->input->post("last_name", true));
$phone = $this->common->nohtml(
$this->input->post("phone", true));
$city = $this->common->nohtml(
$this->input->post("city", true));
$address = $this->common->nohtml(
$this->input->post("address", true));
$jobs = $this->common->nohtml(
$this->input->post("jobs", true));
$education = $this->common->nohtml(
$this->input->post("education", true));
$diplome = $this->common->nohtml(
$this->input->post("diplome", true));
$worktime = $this->common->nohtml(
$this->input->post("worktime", true));
$freeservices = $this->common->nohtml(
$this->input->post("freeservices", true));
$pass = $this->common->nohtml(
$this->input->post("password", true));
$pass2 = $this->common->nohtml(
$this->input->post("password2", true));
$captcha = $this->input->post("captcha", true);
$username = $this->common->nohtml(
$this->input->post("username", true));
if (strlen($username) < 3) $fail = "error_31";
if (!preg_match("/^[a-z0-9_]+$/i", $username)) {
$fail = lang("error_15");
}
if (!$this->register_model->check_username_is_free($username)) {
$fail = lang("error_16");
}
if (!$this->settings->info->disable_captcha) {
if ($captcha != $_SESSION['sc']) {
$fail = lang("error_55");
}
}
if ($pass != $pass2) $fail = lang("error_22");
if (strlen($pass) <= 5) {
$fail = lang("error_17");
}
if (strlen($first_name) > 25) {
$fail = lang("error_56");
}
if (strlen($last_name) > 30) {
$fail = lang("error_57");
}
if (strlen($phone) > 40) {
$fail = lang("error_57");
}
if (strlen($city) > 40) {
$fail = lang("error_57");
}
if (strlen($address) > 400) {
$fail = lang("error_57");
}
if (strlen($jobs) > 80) {
$fail = lang("error_57");
}
if (strlen($education) > 500) {
$fail = lang("error_57");
}
if (strlen($diplome) > 500) {
$fail = lang("error_57");
}
if (strlen($worktime) > 500) {
$fail = lang("error_57");
}
if (strlen($freeservices) > 50) {
$fail = lang("error_57");
}
if (empty($first_name) || empty($last_name)) {
$fail = lang("error_58");
}
if (empty($email)) {
$fail = lang("error_18");
}
if (!valid_email($email)) {
$fail = lang("error_19");
}
if (!$this->register_model->checkEmailIsFree($email)) {
$fail = lang("error_20");
}
if (empty($fail)) {
$pass = $this->common->encrypt($pass);
$active = 1;
$activate_code = "";
$success = lang("success_20");
if($this->settings->info->activate_account) {
$active = 0;
$activate_code = md5(rand(1,10000000000) . "fhsf" . rand(1,100000));
$success = lang("success_33");
// Send email
$this->load->model("home_model");
$email_template = $this->home_model->get_email_template(2);
if($email_template->num_rows() == 0) {
$this->template->error(lang("error_48"));
}
$email_template = $email_template->row();
$email_template->message = $this->common->replace_keywords(array(
"[NAME]" => $username,
"[SITE_URL]" => site_url(),
"[EMAIL_LINK]" =>
site_url("register/activate_account/" . $activate_code .
"/" . $username),
"[SITE_NAME]" => $this->settings->info->site_name
),
$email_template->message);
$this->common->send_email($email_template->title,
$email_template->message, $email);
}
$userid = $this->register_model->add_user(array(
"username" => $username,
"email" => $email,
"first_name" => $first_name,
"last_name" => $last_name,
"phone" => $phone,
"city" => $city,
"address" => $address,
"jobs" => $jobs,
"education" => $education,
"diplome" => $diplome,
"worktime" => $worktime,
"freeservices" => $freeservices,
"password" => $pass,
'picture' => $picture,
"user_role" => 0,
"IP" => $_SERVER['REMOTE_ADDR'],
"joined" => time(),
"joined_date" => date("n-Y"),
"active" => $active,
"activate_code" => $activate_code
)
);
// Check for any default user groups
$default_groups = $this->user_model->get_default_groups();
foreach($default_groups->result() as $r) {
$this->user_model->add_user_to_group($userid, $r->ID);
}
$this->template->set_error_view("succ/regi_succ.php");
$this->template->error(lang("success_20"));
}
}
$this->load->helper("captcha");
$rand = rand(4000,100000);
$_SESSION['sc'] = $rand;
$vals = array(
'word' => $rand,
'img_path' => './images/captcha/',
'img_url' => base_url() . 'images/captcha/',
'img_width' => 150,
'img_height' => 30,
'expiration' => 7200
);
$cap = create_captcha($vals);
$data = array(
"cap" => $cap,
"email" => $email,
"first_name" => $first_name,
"last_name" => $last_name,
"phone" => $phone,
"city" => $city,
"address" => $address,
"jobs" => $jobs,
"education" => $education,
"diplome" => $diplome,
"worktime" => $worktime,
"freeservices" => $freeservices,
'picture' => $picture,
'fail' => $fail,
"username" => $username,
'widget' => $this->recaptcha->getWidget(),
'script' => $this->recaptcha->getScriptTag(),
);
$this->template->loadContent("register/index.php", $data);
}
public function add_username()
{
$this->template->loadExternal(
'<script type="text/javascript" src="'
.base_url().'scripts/custom/check_username.js" /></script>'
);
if (!$this->user->loggedin) {
$this->template->error(
lang("error_1")
);
}
$this->template->loadContent("register/add_username.php", array());
}
public function add_username_pro()
{
$this->load->helper('email');
$email = $this->input->post("email", true);
$username = $this->common->nohtml(
$this->input->post("username", true));
if (strlen($username) < 3) $fail = lang("error_14");
if (!preg_match("/^[a-z0-9_]+$/i", $username)) {
$fail = lang("error_15");
}
if (!$this->register_model->check_username_is_free($username)) {
$fail = lang("error_16");
}
if (empty($email)) {
$fail = lang("error_18");
}
if (!valid_email($email)) {
$fail = lang("error_19");
}
if (!$this->register_model->checkEmailIsFree($email)) {
$fail = lang("error_20");
}
if(!empty($fail)) $this->template->error($fail);
$this->register_model
->update_username($this->user->info->ID, $username, $email);
$this->session->set_flashdata("globalmsg", lang("success_21"));
redirect(site_url());
}
public function check_username()
{
$username = $this->common->nohtml(
$this->input->get("username", true));
if (strlen($username) < 3) $fail = lang("error_14");
if (!preg_match("/^[a-z0-9_]+$/i", $username)) $fail = lang("error_15");
if (!$this->register_model->check_username_is_free($username)) {
$fail="$username " . lang("ctn_243");
}
if (empty($fail)) {
echo"<span style='color:#4ea117'>". lang("ctn_244")."</span>";
} else {
echo $fail;
}
exit();
}
public function activate_account($code, $username)
{
$code = $this->common->nohtml($code);
$username = $this->common->nohtml($username);
$code = $this->user_model->get_verify_user($code, $username);
if($code->num_rows() == 0) {
$this->template->error(lang("error_69"));
}
$code = $code->row();
if($code->active) {
$this->template->error(lang("error_69"));
}
$this->user_model->update_user($code->ID, array(
"active" => 1,
"activate_code" => ""
)
);
$this->session->set_flashdata("globalmsg",
lang("success_34"));
redirect(site_url("login"));
}
public function send_activation_code($userid, $email)
{
$userid = intval($userid);
$email = $this->common->nohtml(urldecode($email));
// Check request
$request = $this->user_model->get_user_event("email_activation_request");
if($request->num_rows() > 0) {
$request = $request->row();
if($request->timestamp + (15*60) > time()) {
$this->template->error(lang("error_70"));
}
}
$this->user_model->add_user_event(array(
"event" => "email_activation_request",
"IP" => $_SERVER['REMOTE_ADDR'],
"timestamp" => time()
)
);
// Resend
$user = $this->user_model->get_user_by_id($userid);
if($user->num_rows() == 0) {
$this->template->error(lang("error_71"));
}
$user = $user->row();
if($user->email != $email)
{
$this->template->error(lang("error_71"));
}
if($user->active) {
$this->template->error(lang("error_71"));
}
// Send email
$this->load->model("home_model");
$email_template = $this->home_model->get_email_template(2);
if($email_template->num_rows() == 0) {
$this->template->error(lang("error_48"));
}
$email_template = $email_template->row();
$email_template->message = $this->common->replace_keywords(array(
"[NAME]" => $user->username,
"[SITE_URL]" => site_url(),
"[EMAIL_LINK]" =>
site_url("register/activate_account/" . $user->activate_code .
"/" . $user->username),
"[SITE_NAME]" => $this->settings->info->site_name
),
$email_template->message);
$this->common->send_email($email_template->title,
$email_template->message, $user->email);
$this->session->set_flashdata("globalmsg",
lang("success_35"));
redirect(site_url("login"));
}
}
?>
答案 0 :(得分:0)
希望这对您有帮助:
从您的配置中删除$config['xss_clean'] = TRUE;
您要上传的config
应该是这样的:
$config['upload_path'] = FCPATH .'uploads/images/';
$config['allowed_types'] = 'jpg|jpeg|png';
$config['encrypt_name'] = TRUE;
$config['overwrite'] = FALSE;
$config['max_filename'] = 300;
$config['remove_spaces'] = TRUE;
$config['max_size'] = 2048;
$this->load->library('upload',$config);
if($this->upload->do_upload('picture'))
{
$picture = $this->upload->data('file_name');
}else
{
$picture = '';
}