CodeIgniter Forums
Help Needed : Upload File Exists Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Help Needed : Upload File Exists Validation (/thread-11775.html)



Help Needed : Upload File Exists Validation - El Forum - 09-22-2008

[eluser]aslamdoctor[/eluser]
I am trying to develop a code to validate that the file which is about to upload is already exists or not,

for that I have to do something as following

Code:
if(!file_exists($config['upload_path'].$filename))
{
      $this->upload->do_upload();
}
else
{
      echo "File exists..."
}

now the problem here is, how do I get the $filename, if I use $_FILES , it will give the actual file name,
here I need the filename that CI generates during uploading by reducing special characters.


Help Needed : Upload File Exists Validation - El Forum - 09-23-2008

[eluser]David Cassidy[/eluser]
The Upload library automatically checks whether or not the file exists. If so, it appends a sequential number to the end of the filename. You can change this behaviour if you like by extending the Upload class, or editing lines 358-377 in /system/libraries/Upload.php.

If you are just wanting a quick way to format the filename the way CodeIgniter does, the clean_file_name() method is a public function which means you can do:

Code:
if(!file_exists($config['upload_path'].$this->upload->clean_file_name($filename)))
{
      $this->upload->do_upload();
}
else
{
      echo "File exists..."
}

...to get the desired results.


Help Needed : Upload File Exists Validation - El Forum - 09-24-2008

[eluser]aslamdoctor[/eluser]
Sorry, "clean_file_name()" is not for that purpose.

actually it worked with this


Code:
preg_replace("/\s+/", "_", $_FILES['userfile']['name'])