get error when upload image in pathinfo() with code igniter - php

i have method for uploading image, but i get multiple error messages if i run this method with error:
Severity: Warning
Message: pathinfo() expects parameter 1 to be string, array given
Filename: core/Loader.php
Line Number: 759
Severity: Notice
Message: Array to string conversion
Filename: core/Loader.php
Line Number: 760
An Error Was Encountered
Unable to load the requested file: Array.php
how do I fix the code so as not to get an error ? where is the problem ?
thanks
function upload_image()
{
$config = array(
'file_name'=> 'hallo.jpg',
'upload_path'=>'./application/views/photo',
'allowed_types'=>'gif|jpg|png',
'max_size'=>'1024',
'max_width'=>'1600',
'max_height'=>'1200'
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data['breadcrumb1'] = "Member";
$data['breadcrumb'] = "Add Member";
$data['content']='admin-cms/member/add';
$this->load->view('admin-cms/index', $data);
}else
{
$data['content']= array('error' => $this->upload->display_errors('<span class="error">','</span>'));
$this->load->view('admin-cms/index', $data);
}
}

Related

How to reference a Class Method using an array variable in PHP7?

I've moved from PHP5 to PHP7.
The following code no longer works.
<?php
class sandbox {
function doit() {
$method = array('name' => 'testresponse');
return $this->$method['name']();
}
function testresponse(){
return "Hi!";
}
}
$h = new sandbox();
echo "Hello, " . $h->doit();
I'm wondering what is the new syntax for this?
Here are the PHP errors I'm getting
A PHP Error was encountered Severity: Notice
Severity: Notice
Message: Array to string conversion
Filename: front/sandbox.php
Line Number: 20
And
Fatal error: Uncaught Error: Function name must be a string in /var/www/application/controller/sandbox.php:20 Stack trace: #0
Change this
return $this->$method['name']();
to this
return $this->{$method['name']}();

codeigniter 2 with doctrine 2 - I can insert data in to tables but I can't get data back

I am still trying to study doctrine so I am following online tutorial by that I could insert data in to a mysql table. like this.
public function createObjects() {
// create a new user object
$user = new Entities\User;
$user->setFirstName('Joel');
$user->setLastName('Verhagen');
$user->setPassword(md5('Emma Watson'));
$this->doctrine->em->persist($user);
$this->doctrine->em->flush();
}
Then I tried to get the data back like this.
public function testing() {
// $user = new Entities\User;
$article = new Entities\Article;
$firstname = $this->doctrine->em->getRepository($article);
$products = $firstname->findAll();
foreach ($products as $product) {
echo sprintf("-%s\n", $product->getContent());
}
}
But I am getting following errors can some one help me on this?
Severity: Warning
Message: ltrim() expects parameter 1 to be string, object given
Filename: ORM/EntityManager.php
Severity: Warning
Message: class_parents(): object or string expected
Filename: Mapping/RuntimeReflectionService.php
Severity: Warning
Message: array_reverse() expects parameter 1 to be array, boolean given
Filename: Mapping/AbstractClassMetadataFactory.php
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: Mapping/AbstractClassMetadataFactory.php
Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php:73 Stack trace: #0 E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php(73): ReflectionClass->__construct('') #1 E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Mapping\ClassMetadataInfo.php(867): Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getClass(NULL) #2 E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php(517): Doctrine\ORM\Mapping\ClassMetadataInfo->initializeReflection(Object(Doctrine\Common\Persistence\Mapping\RuntimeReflectionService)) #3 E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(300): Doctrine\ORM\Mapping\ClassMetadataFactory->initializeReflection(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(Doctrine\Common\Pe in E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php on line 73
Tried and tried and at last I found a way to go.
public function testing() {
// $user = new Entities\User;
$article = new Entities\Article;
$firstname = $this->doctrine->em->getRepository('Entities\Article');
$products = $firstname->findAll();
foreach ($products as $product) {
echo sprintf("-%s\n", $product->getContent());
}
// $products = $article->getContent();
// echo $products.'fdsf';
}

How to create an image watermark wm_type overlay in Codeigniter?

I am trying to put an image over another image (watermark) like so:
class Water_mark extends CI_Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->load->library('image_lib');
$config['image_library'] = 'GD2';
$config['source_image'] = '/assets/images/tv-share.jpg';
$config['new_image'] = '/assets/images/tv-share-done.jpg';
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = '/assets/images/share_en.jpg';
$config['wm_opacity'] = '50';
$config['wm_vrt_alignment'] = 'top';
$config['wm_hor_alignment'] = 'left';
$config['wm_hor_offset'] = '10';
$config['wm_vrt_offset'] = '10';
$data = $config;
$this->image_lib->initialize($config);
if (!$this->image_lib->watermark()) {
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
$this->load->view('water_mark_view', $data);
}
}
but I keep getting errors:
A PHP Error was encountered
Severity: Warning
Message: imagecolorat() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 941
A PHP Error was encountered
Severity: Warning
Message: imagecolorat() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 953
A PHP Error was encountered
Severity: Warning
Message: imagecolortransparent() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 953
A PHP Error was encountered
Severity: Warning
Message: imagecopymerge() expects parameter 1 to be resource, boolean given
Filename: libraries/Image_lib.php
Line Number: 954
The path to the image is not correct.
The path to the image is not correct.
The path to the image is not correct.
Your server does not support the GD function required to process this type of image.
Your server does not support the GD function required to process this type of image.
Your server does not support the GD function required to process this type of image.
What am I missing?
The issue was as simple as removing the forward slash (although in the documentation example the forward slash exists) at he beginning like so:
$config['source_image'] = 'assets/images/tv-share.jpg';
$config['new_image'] = 'assets/images/tv-share-done.jpg';
$config['wm_overlay_path'] = 'assets/images/share_en.jpg';
what got me confused this error:
Your server does not support the GD function required to process this
type of image.
I never thought it was only a path issue when I saw the error above.

codeigniter acsess data with query

I have an error in my project, can you please help me? Here's my code :
$q_cek_login = $this->db->get_where('tbl_karyawan', array('username' => $u, 'password' => $p));
if(count($q_cek_login->result())>0)
{
foreach($q_cek_login->result() as $qck)
{
if($qck->id_jabatan==1)
{
foreach($q_cek_login->result() as $qad)
{
$sess_data['logged_in'] = 'yesGetMeLogin';
$sess_data['username'] = $qad->username;
$sess_data['nama_pengguna'] = $qad->nama;
$sess_data['id_jabatan'] = $qad->id_jabatan;
$this->session->set_userdata($sess_data);
}
//header('location:'.base_url().'pemesanan/pending');
}
}
}
Then I get this error :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$id_jabatan
Filename: models/model_digor.php
Line Number: 26
thx u all..........
Please check your dependency class is loaded properly. such as $this->load->library('database'); or $this->load->library('your_built_in_class');

codeigniter class error

For some reason i cant get my model to work.. never had this problem before.
function overview($userid)
{
// Load needed model
$this->load->model('budget_model');
$data['month_budget'] = $this->budget_model->get_monthly_budget($userid);
if(isset($_POST['submit']))
{
foreach($_POST as $key => $value)
{
if(is_numeric($key))
{
$this->buget_model->update_buget($key,$value);
echo "DONE";
}
}
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
$data['main'] = 'super_admin/budget_edit_overview_view';
$this->load->view('default/main_view',$data);
}
The model works fine with "$this->budget_model->get_monthly_budget($userid);" but i keep getting thir error,
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Admin::$buget_model
Filename: controllers/admin.php
Line Number: 166
Fatal error: Call to a member function update_buget() on a non-object
in /Applications/MAMP/htdocs/therace/application/controllers/admin.php
on line 166
The model method,
function update_buget($id,$budget)
{
$this->db->where('id', $id);
// Update the month budget
$data = array(
'month_goal' => $budget
);
$this->db->update('budget_month', $data);
return true;
}
Read the error message carefully:
Message: Undefined property: Admin::$buget_model
Did you make a typo and actually mean $budget_model?
edit: There seems to be a lot of budget vs. buget in your code. I suggest a spellchecker.
You have made a typing error in line 166.
It is $this->budget_model->update_buget($key,$value);
not $this->buget_model->update_buget($key,$value);

Categories