• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading files into root directory folders in CodeIgniter.

#1
I have 5 problems, the 5th is a potential problem. It is probably best to deal with one problem at a time.

(1) The posted information does not load into the folders. I have tried deleting the country folder but it makes no difference.

(2) If a different Username is used it declares an error that the Username exists. The is_unique function is not working. I have tried deleting the country folder but it makes no difference.

(3) When the root folder is deleted the above errors are the same as when the folder exists.

(4) I have tried to check if username exists in the members folder, as per the coding below but that coding doesn't work.

(5) Will need to login when the information is loaded, using the Username & Password.

Basically, the coding below was taken from another person's project, which worked, but I have changed things to suit my project and the difference with that other person's project and what I'm trying to do is that the Username and Password information was loaded into a database, whereas I don't want to use a database. In that other project the Certificate was loaded into a folder in the root directory the same as what I'm trying to do, but I also want to load the Username and Password into the root directory folders the same as the Certificate. Also in that other person's project there was no country folder. All of that maybe the cause of my problems but I don't know how to fix, despite studying the CI UserGuide.

The coding below creates the folders in the root directory as expected and as follows.

accounts/afghanistan/realname/username
accounts/afghanistan/realname/password
accounts/afghanistan/realname/certificate

But no information or pdf files are entered.

I would want the Username & Password information to be in PHP format.

Controller

PHP Code:
public function youraccount()
{

$error 0;
$realname "";
$certificate "";
$username "";
$password "";

$this->load->helper(array('form''url','file'));
$this->load->library('form_validation');
$this->load->library('upload');

if(isset(
$_POST['submit']))
$config = array(
array(
'field'=>'realname''label' => 'RealName''rules' => 'required|is_unique[user]''errors' => array('required' => 'Provide the %s''is_unique' => 'This %s already exists' )),
array(
'field'=>'username''label' => 'Username''rules' => 'required''errors' => array( 'required' => 'Provide the %s')),
array(
'field'=>'password''label' => 'Password''rules' => 'required''errors' => array( 'required' => 'Provide the %s')),
array(
'field'=>'certificate''label' => 'Certificate''rules' => 'callback_upload_certificate'));

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

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

{
$this->load->view('afghanistan/youraccount');
}
else
{

$realname $this->input->post('realname');
$username $this->input->post('username');
$password $this->input->post('password');
$certificate $this->input->post('certificate');

//check if username exists.
if(!is_dir('members/$username'))
$this->user_name->set_message('$username''The username does not exist');

//check if accounts dir exists. Otherwise, create the 'accounts' folder.
if(!is_dir('accounts/afghanistan'))

{
mkdir('accounts/afghanistan',0777,true);
}

//create folder to the project dir
mkdir('accounts/afghanistan/'.$realname.'/username',0777,true);
mkdir('accounts/afghanistan/'.$realname.'/password',0777,true);
mkdir('accounts/afghanistan/'.$realname.'/certificate',0777,true);

$config['upload_path'] = 'accounts/afghanistan/'.$youraccount->realname.'/certificate/';
$config['allowed_types'] = 'pdf';

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

if (
$this->upload->do_upload('certificate'))

{
$img $this->upload->data();
$certificate 'accounts/afghanistan/'.$youraccount->realname.'/certificate/'.$img['file_name'];
}

redirect(BASE_URL.'afghanistan/login');

}

}
else
{

$this->load->view('afghanistan/youraccount');

}
}

public function 
upload_certificate($str)
{

$allowed_mime_type_arr = array('application/pdf');

if(isset(
$_FILES['certificate']['name']) && $_FILES['certificate']['name']!="")
{

$mime get_mime_by_extension($_FILES['certificate']['name']);

if(
in_array($mime$allowed_mime_type_arr))

{
return 
TRUE;
}
else
{

$this->form_validation->set_message('upload_certificate''Upload the Certificate in pdf format');

return 
FALSE;

}
}
else
{

$this->form_validation->set_message('upload_certificate''Provide the Certificate');

return 
FALSE;

}


View

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<title>YourAccount</title>

<style type="text/css"> .rname { position: fixed; width: 100%; } </style>
<style type="text/css"> .valida { position: fixed; width: 100%; } </style>
<style type="text/css"> .uname { position: fixed; width: 100%; } </style>
<style type="text/css"> .validb { position: fixed; width: 100%; } </style>
<style type="text/css"> .pword { position: fixed; width: 100%; } </style>
<style type="text/css"> .validc { position: fixed; width: 100%; } </style>
<style type="text/css"> .cert { position: fixed; width: 100%; } </style>
<style type="text/css"> .validd { position: fixed; width: 100%; } </style>

</head>
<body>

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

<div class="rname"> <input type="text" value="<?php echo isset($_POST['realname']) ? $_POST['realname'] : '';?>" name="realname" style="width: 10%; height: 5mm"; > </div>
<div class="valida"><?php echo form_error('realname'); ?> </div>
<div class="uname"> <input type="text" value="<?php echo isset($_POST['username']) ? $_POST['username'] : '';?>" name="username" style="width: 10%; height: 5mm"; ></div>
<div class="validb"><?php echo form_error('username'); ?> </div>
<div class="pword"> <input type="password" value="<?php echo isset($_POST['password']) ? $_POST['password'] : '';?>" name="password" style="width: 5%; height: 5mm"; ></div>
<div class="validc"><?php echo form_error('password'); ?> </div>
<div class="cert"> <input type="file" name="certificate" id="certificate" style="width: 100%; height: 5mm"; > </div>
<div class="validd"><?php echo form_error('certificate'); ?> </div>
<div class="sub"> <div><input type="submit" value="Submit" name="submit" ></div></form>

</body>
</html 

I want the information that is entered into the text boxes and the pdf file to be loaded into the root directory folders.

UPDATE 08/08/19

I've changed this line-
PHP Code:
$config['upload_path'] = 'accounts/afghanistan/'.$youraccount->realname.'/certificate/'

To this-
PHP Code:
$config['upload_path'] = 'accounts/afghanistan/'.$realname.'/certificate/'

Now I have the pdf certificate loading into the folder.

UPDATE 16/08/19

I've added the following to the above Controller script, but that shouldn't change the performance or add or reduce the problems.

PHP Code:
if(!is_dir('accounts'))
{
mkdir('accounts',0777,true);
}
//check if accounts/afghanistan dir exists. Otherwise, create the 'accounts/afghanistan' folder. 

I now get the accounts & country folders created and the "first" RealName folder is created and the Username, Password, and Certificate subfolders are created. And as I said in the last update the pdf certificate loads into the folder.

But I now have 2 additional problems.

(1) With is_unique enabled every additional RealName produces the error "already exists" when there is no other existing.

(2) If I disable is_unique I can not create subsequent RealName folders, in other words "second" or "third" RealName folders. I have tried creating another Country folder which works but I can only use the "first" RealName. Or put another way if I use "John Doe" as the "first" RealName I can not use "Bill Smith" or "Joe Blog" as "second" or "third" RealNames as the folders will not create, but the "John Doe" folder will create and regardless of which country.

Those 2 problems appear to be CodeIgniter bugs because I've tried numerous variations of coding.

Or does somebody have the solution?

Also, I need to learn how to transfer the contents of the text boxes into a PHP file. I guess there should be a template PHP file that is copied and then the text box content added, then the copied file loaded into the folders the same as the PDF file is loaded into the Certificate folder.

Can that be done in CodeIgniter or maybe Javascript?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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