• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant get photo to upload.

#1
Im trying to create an advert template but can not get the photos to upload. I dont receive any errors. Ive simplified the coding so that it focuses only on the uploading of one photo, as follows;

This is the Controller coding;
PHP Code:
public function drinkadvert()
    {
    
$this->load->library('image_lib');
    
$this->load->helper(array('form','file'));
    
$this->load->library('upload');

        
$lcuser $this->session->userdata('user_name');
        
$drink $this->input->post('dri');
        
$drinkphoto $this->input->post('drinkphoto');

        {
        
$this->load->view('affairs/drinkadvert');
        }

        
$config['upload_path'] = 'mem/'.$lcuser.'/adverts/'.$drink;
        
$config['allowed_types'] = 'png|jpg|jpeg';

        
$this->upload->initialize($config);

        if(
$this->upload->do_upload("$drinkphoto"))

        {
        
$img $this->upload->data();
        
$drinkphoto 'mem/'.$lcuser.'/adverts/'.$drink/$img['file_name']; //The problem may lie in the file_name but I dont know much about that.
        
}
    }

public function 
upload_drinkphoto($str)
    {
    
$allowed_mime_type_arr = array('image/png','image/jpg','image/jpeg');

    if(isset(
$_FILES['drinkphoto']['name']) && $_FILES['drinkphoto']['name']!="")
        {
            
$mime get_mime_by_extension($_FILES['drinkphoto']['name']);

        if(
in_array($mime$allowed_mime_type_arr))
            {
            return 
TRUE;
            }
            else
            {
            
$this->form_validation->set_message('upload_drinkphoto''Upload in png/jpg/jpeg format');
            return 
FALSE;
            }
        }
    } 
This is the view coding.
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?>
<body>

<?php echo form_open_multipart('drinkadvert'); ?>

<style type="text/css"> .drinkpic { position: fixed; width: 28%; right: 8%; top: 34%; background-color: White; } </style>
    <div class="drinkpic"> <input type="file" name="drinkphoto" id="drinkphoto" style="width: 100%; height: 5mm"; > </div>

<style type="text/css"> .sub { position: fixed; width: 5%; right: 19%; text-align: center; top: 83.5%; } </style>
    <div class="sub"> <input type="submit" value="Submit"></form></div> 

The remedy to this problem must be simple. Can anybody tell me what it is?
Reply

#2
Try this and see if it works.

PHP Code:
$config['upload_path'] = './mem/'.$lcuser.'/adverts/'.$drink

Remember the path for the file has to have write access also.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(10-02-2020, 06:56 PM)InsiteFX Wrote: Try this and see if it works.

PHP Code:
$config['upload_path'] = './mem/'.$lcuser.'/adverts/'.$drink

Remember the path for the file has to have write access also.

Nope, that made no difference, but thanks. Im getting desperate.
Reply

#4
You can try giving it the Absolute path or relative path.

As it is now I would try them both.

You did not mention if this was running on localhost or a live server?
Also what OS are you running?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(10-03-2020, 02:40 AM)InsiteFX Wrote: You can try giving it the Absolute path or relative path.

As it is now I would try them both.

You did not mention if this was running on localhost or a live server?
Also what OS are you running?

I guess you mean "position:" in the view page. Ive had it on "fixed" but "relative" & "absolute" make no difference.

Running localhost. OS Windows. Ive tried backslash \ separator on one page a while ago & it didnt work.

The coding Ive provided, including the forward slash separators /, has worked OK on other pages.
Reply

#6
(10-03-2020, 02:40 AM)InsiteFX Wrote: You can try giving it the Absolute path or relative path.

As it is now I would try them both.

You did not mention if this was running on localhost or a live server?
Also what OS are you running?

Ive just tried;
PHP Code:
$config['upload_path'] = 'mem/'.$lcuser.$drink;
$drinkphoto 'mem/'.$lcuser.$drink/$img['file_name']; 
And
PHP Code:
$config['upload_path'] = 'mem/'.$drink;
$drinkphoto 'mem/'.$drink/$img['file_name']; 
But still no upload. That tells me it probably is wrong in the upload coding rather than the path.
Reply

#7
I think I see what is wrong now in your form_open you only have the function name
it should be controller/function your missing the controller name controller/function ( method ).
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#8
(10-03-2020, 07:20 AM)InsiteFX Wrote: I think I see what is wrong now in your form_open you only have the function name
it should be controller/function your missing the controller name controller/function ( method ).

I dont understand. Do you mean "public function drinkadvert()" must be the same name "drinkadvert" <?php echo form_open_multipart('drinkadvert'); ?> They are the same.
Reply

#9
What is the name of the controller that the function is in?

PHP Code:
<?php echo form_open_multipart('controllerName/drinkadvert'); ?>

Change controllerName to the name of your controller that the drinkadvert is in.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#10
(10-03-2020, 10:20 AM)InsiteFX Wrote: What is the name of the controller that the function is in?

PHP Code:
<?php echo form_open_multipart('controllerName/drinkadvert'); ?>

Change controllerName to the name of your controller that the drinkadvert is in.

I had the Controller name shortened by $route. But I tried it the long way & still did not upload. When that name is incorrect it gives an error but Im not getting any errors.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.