Welcome Guest, Not a member yet? Register   Sign In
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


Messages In This Thread
mkdir and fopen not creating files - by christaliise - 09-15-2020, 10:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB