Welcome Guest, Not a member yet? Register   Sign In
Upload problem
#1

[eluser]Gazzhop[/eluser]
view:
Code:
<?php echo form_open_multipart('image_manager/do_upload');?>
<table>
    <tr>
        <th>Select image you wish to upload</th>
    </tr>
    <tr>
        <td>&lt;?php echo form_upload('userfile');?&gt;</td>
    </tr>
    <tr>
        <td>&lt;?php echo form_submit('submit', 'Upload')?&gt;</td>
    </tr>
</table>

controller

Code:
&lt;?php
class image_manager extends Controller {

    function image_manager()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));  
    }
    
    function index()
    {
        
        
        $this->load->helper('directory');
        $map = directory_map(file_url(), TRUE);
        $this->load->view('header');      
  
        $this->load->view('image_manager_view', array('error' => ' ', 'map'=>$map ));
        
        $this->load->view('footer', array("logged_in"=>TRUE));    
    }
    
    function do_upload()
    {
        $config['upload_path'] = 'http://localhost:8888/PDCRARE/images/';
        $config['allowed_types'] = 'gif|jpg|png|bmp';
        $config['max_size'] = '0';
        $config['max_width'] = '0';
        $config['max_height'] = '0';
        $config['overwrite'] = TRUE;
                
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        if ( ! $this->upload->do_upload('userfile'))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('header');
            $this->load->view('image_manager_view', $error);
            $this->load->view('footer', array("logged_in"=>TRUE));
            
        }  
        else
        {
            $data = array('upload_data' => $this->upload->data());
          
            $this->load->view('header');
            $this->load->view('image_upload_success', $data);
            $this->load->view('footer', array("logged_in"=>TRUE));
        }
        
        
              
    }  
    
    
    
    
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
?&gt;

MY_Url_helper

Code:
if ( ! function_exists('file_url'))
{
    function file_url($controller = false)
    {
        if($controller)
           return '../CMS_PDCRARE/images';
        else
           return '../CMS_PDCRARE/images';
    }

PROBLEM:

I keep getting path invalid error, but can't see what i'm doing wrong. Sorry if this is simple noob problem.
#2

[eluser]gunter[/eluser]
Code:
$config['upload_path'] = 'http://localhost:8888/PDCRARE/images/';

bad boy! you cannot use a http: adress as upload path... instead use something like...
Code:
"./PDCRARE/images/"
thats an example... I donĀ“t know where your directory is...
normally, if you are using this:
Code:
$config['upload_path'] = './uploads/';
then your upload folder is in the same folder like the index.php file
#3

[eluser]NateL[/eluser]
Yeah you need your document root. You can find it by using this code:

Code:
&lt;?php echo $_SERVER['DOCUMENT_ROOT']; ?&gt;
#4

[eluser]Gazzhop[/eluser]
I have added the code
Code:
echo $_SERVER['DOCUMENT_ROOT'];

and it brings up /var/www/html
so I add /CMS_PDCRARE/images/ as the directory path and chmod 777 the images directory.

But still gets the error.

tried ./ as the directory path and I get the success page but image not uploaded anywhere.

I must be doing something stupidly wrong but can't fathom what it is!!!
#5

[eluser]IkoTikashi[/eluser]
You need the full path: /var/www/html/CMS_PDCRARE/images/. To be on the save side when you switch servers, use
Code:
"{$_SERVER['DOCUMENT_ROOT']}/CMS_PDCRARE/images/"
#6

[eluser]Gazzhop[/eluser]
Solved! thanks, I have another question:

in /var/www/html I have two sites main and the CMS.

I have created a form and want to dump out the images in the main site's image folder into options (so they can be assigned).
But when I use
Code:
$this->load->helper('directory');
$pics = directory_map($_SERVER['DOCUMENT_ROOT'] . "/MAIN/images";
$this->load->view('Assign', 'pics'=>$pics);

view
Code:
foreach($pics as $row){
print "<option value='" . $row . "'>" . $row . "</option>";
}

I get no options, what have I done wrong?




Theme © iAndrew 2016 - Forum software by © MyBB