Welcome Guest, Not a member yet? Register   Sign In
I can't Upload File
#1

[eluser]harly[/eluser]
I save code in my server but mycode problem in server. but i'm running in my pc ( localhost) no problem.
please help me.


Error:
Fatal error: Call to a member function do_upload() on a non-object in


mycode:
function upload(){
$config['upload_path'] = 'upload/';
$config['allowed_types'] = 'pdf|jpeg|jpg';
$config['file_name'] = $data;
$config['max_size'] = '1000000';

$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
echo "warnin";
}else {
echo "succes";
}
}
#2

[eluser]jedd[/eluser]
[quote author="harly" date="1258581648"]
I save code in my server but mycode problem in server. but i'm running in my pc ( localhost) no problem.
[/quote]

Hi harly and welcome to the CI forums.

You may want to read through [url="http://codeigniter.com/wiki/How_to_ask_a_good_question/"]guide to asking a good question[/url] and then trying this one again.

You say your code works on one computer, but not another - it's not clear if you've read through the [url="/wiki/FAQ"]FAQ section[/url] on solving problems with moving between different platforms, and you haven't mentioned what the two operating systems are, what the differences are between the two platforms as you've configured them, database differences, what you've tried already to solve the problem, and so on.
#3

[eluser]CI_avatar[/eluser]
maybe your link sets to localhost even you have transfered the your system to other machine. it is wise not to use localhost, you have to practice using your IP not localhost. if you access you page from remote with localhost configuration you will get an error. please change it to your IP.

like:

http://localhost/code_igniter/uploads to
http://your.ip.here./code_igniter/uploads
#4

[eluser]harly[/eluser]
code controller/Upload.php
<?php

class Upload extends Controller {

function Upload() {
parent::Controller();
// $this->load->helper('form');
}

function index() {
$this->load->view('upload_form');
}

function doUpload() {
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';

$this->load->library('upload', $config);

if(!$this->upload->do_upload()) echo $this->upload->display_errors();
else {
$fInfo = $this->upload->data();
$this->_createThumbnail($fInfo['file_name']);

$data['uploadInfo'] = $fInfo;
$data['thumbnail_name'] = $fInfo['raw_name'] . '_thumb' . $fInfo['file_ext'];
$this->load->view('upload_success', $data);
}
}

function _createThumbnail($fileName) {
$config['image_library'] = 'gd2';
$config['source_image'] = 'uploads/' . $fileName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 75;

$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}
}

code view/upload_form

<div id="container">
<h2>Upload an Image </h2>

&lt;?php echo form_open_multipart('upload/doUpload'); ?&gt;
&lt;input type="file" name="userfile" /&gt;
<p>&lt;input type="submit" value="Submit" name="submit" /&gt;&lt;/p>
&lt;?php echo form_close(); ?&gt;
</div>


yesterday i'm try download code tutorial in website. upload image and crop.
i running code in pc windows no problem but my code running in server linux problem.


ERROR:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Upload::$upload

Filename: controllers/upload.php

Line Number: 25

Fatal error: Call to a member function do_upload() on a non-object in /hermes/bosweb/web122/b1228/sl.????/public_html/imageupload/application/controllers/upload.php on line 25
#5

[eluser]jedd[/eluser]
Try renaming Upload.php to upload.php for starters (just opening the rar within the zip that you've sent, and this stands out).
#6

[eluser]harly[/eluser]
I've tried but still same error.
#7

[eluser]jedd[/eluser]
Code:
if(!$this->upload->do_upload()) echo $this->upload->display_errors();
else {
   $fInfo = $this->upload->data();

Never write code like this - it's very hard to read, and makes error messages less useful (a line number indicator doesn't reveal which of those two functions is failing).

On that note, your code that you've provided in the rar file doesn't match the error you mentioned - the line numbering is wrong. Can you please re-post your current code and your current error message(s) verbatim?
#8

[eluser]Unknown[/eluser]
Im also so guilty of capitalizing the first letter of a filename, it just comes naturally, caused me all sorts of headaches and wasted time !!!
#9

[eluser]harly[/eluser]
please download my code

code trouble in server(linux) not pc(windows)
#10

[eluser]jedd[/eluser]
I've run this code - 1 x controller, 2 x views - on a vanilla CI install on my linux box, and it works fine. The only change I had to make was uncommenting your form helper loading in the constructor.

I suggest the problem is therefore elsewhere in your system, and the best bet might be to grab a new copy of CI, unpack it somewhere, make the config.php base_url change, and copy these three files in as I've just done. Until you've done that we're just guessing at which direction to look for the source of your problems here.




Theme © iAndrew 2016 - Forum software by © MyBB