Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter -> File Upload Path | Folder Create

Currently I have the following:

$config['upload_path'] = 'this/path/location/';

What I would like to do is create the following controller but I am not sure how to attack it!!

$data['folderName'] = $this->model->functionName()->tableName;

$config['upload_path'] = 'this/'.$folderName.'/';

How would I create the $folderName? dictionary on the sever?

Jamie:

Could I do the following?

if(!file_exists($folderName))
{

  $folder = mkdir('/location/'$folderName);

   return $folder; 
}
else
{
 $config['upload_path'] = $folder; 
}
like image 207
Jess McKenzie Avatar asked Dec 21 '22 23:12

Jess McKenzie


2 Answers

am not sure what they are talking about by using the file_exist function since you need to check if its the directory ..

$folderName = $this->model->functionName()->tableName;
$config['upload_path'] = "this/$folderName/";
if(!is_dir($folderName))
{
   mkdir($folderName,0777);
}

please note that :

  1. i have added the permission to the folder so that you can upload files to it.
  2. i have removed the else since its not useful here ( as @mischa noted )..
like image 83
Zaher Avatar answered Dec 23 '22 12:12

Zaher


This is not correct:

if(!file_exists($folderName))
{
   mkdir($folderName);
}
else
{
   // Carry on with upload
}

Nothing will be uploaded if the folder does not exist! You have to get rid of the else clause.

$path = "this/$folderName/";

if(!file_exists($path))
{
   mkdir($path);
}

// Carry on with upload
$config['upload_path'] = $path; 
like image 38
Mischa Avatar answered Dec 23 '22 14:12

Mischa