• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mkdir and fopen not creating files

#1
Im trying to create an advert template for users to place an advert, although I can get the validation to work, the rest does not work.

I think it is caused by the user variable being incorrect somewhere.

This is the edited coding;

PHP Code:
public function drinkadvert()
    {
    
$this->load->library('session');
    
$this->load->helper('url');
    
$this->load->library('upload');
    
$this->load->library('image_lib');
    
$this->load->library('form_validation');

        
$config = array(
        array(
'field' => 'dri''label' => 'Drink''rules' => 'required''errors' => array( 'required' => 'Provide%s')), //This works
        
array('field' => 'drink''label' => 'Photo''rules' => 'callback_upload_drink')); //This works

        
$this->form_validation->set_rules($config);

        if(
$this->form_validation->run() == FALSE// Every box is complete

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

        
$lcuser $this->session->userdata('user_name');
        
$ucuser ucfirst("$lcuser");

        
$drink $this->input->post('dri');

        if(!
is_dir("C:xampp/htdocs/application/controllers/Adverts/$ucuser/"))

            
mkdir("C:xampp/htdocs/application/controllers/Adverts/$ucuser/",0777,true); //This does not create

        
if(!is_dir("C:xampp/htdocs/application/controllers/Adverts/$ucuser/$drink"))

            
mkdir("C:xampp/htdocs/application/controllers/Adverts/$ucuser/$drink",0777,true); //This does not create

        //Upload Photos

            
$config1['upload_path'] = 'members/'.$lcuser.'/advertphotos/'.$drink;
            
$config1['allowed_types'] = 'png|jpg|jpeg';

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

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

            {
            
$drink $this->upload->data();
            
$drink 'members/'.$lcuser.'/advertphotos/'.$drink['file_name']; //This does not upload
            
}
        }
    }

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

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

        if(
in_array($mime$allowed_mime_type_arr))
            {
            return 
TRUE;
            }
            else
            {
            
$this->form_validation->set_message('upload_drink''Upload in png/jpg/jpeg format');
            return 
FALSE;
            }
        }
        else
        {
        
$this->form_validation->set_message('upload_drink''ProvideAtLeastOnePhoto');
        return 
FALSE;
        }
    }

public function 
create_advert()
    {

$create fopen("C:xampp/htdocs/application/controllers/Adverts/$ucuser/$drink.php""w"); //This does not create
$cr "<?php .................

$create = fopen("C:xampp/htdocs/application/views/adverts/$lcuser/$drink.php", "w"); //This does not create
$cr = "<?php .................

        
redirect('adverts/.$ucuser.$drink');
    } 

Ive used all the functions on other pages which work OK, and Ive checked the coding that works against the coding above but cant find anything wrong.

Can anybody tell me what is wrong.
Reply

#2
Maybe add the forward / C:/
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(09-16-2020, 01:17 PM)InsiteFX Wrote: Maybe add the forward / C:/

Nope, that made no difference.
Reply

#4
For one take off the ending slash it's not needed.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(09-17-2020, 04:30 AM)InsiteFX Wrote: For one take off the ending slash it's not needed.

Ive deleted the ending slash.

Ive solved some of my problems, but not all.

If I comment out the form_validation & shift loadview below the mkdir I can get the directories to create the way I want.

That tells me that there is nothing wrong with the user variables, and either the "form_validation" or the "else" is at fault but I havent yet found which one because the photos do not upload nor does the create_advert function work.

Ive tried inserting into various places
PHP Code:
if(isset($_POST['submit'])) 
but nothing.

Ive tried encasing the form_validation with curly brackets {....} but that doesnt help.

If I comment out the photos upload and create_advert and have form_validation with mkdir only, the directories still dont create, which tells me the problem is not associated with the photos upload or the create_advert.

Ive tried commenting out the upload of photos to see if the create_advert function works but it doesnt, in fact that process distorts the textareas but altering the view page may fix that.
Reply

#6
Ive made many changes and got everything to work except the uploading of photos. I'll post a new topic regarding photos wont upload.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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