CodeIgniter Forums
File Uploading class - how to retrieve filename before uploading file? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: File Uploading class - how to retrieve filename before uploading file? (/showthread.php?tid=23676)



File Uploading class - how to retrieve filename before uploading file? - El Forum - 10-19-2009

[eluser]stuart_g[/eluser]
I would like to know the filename of the file before I upload it, as I want to inform the user it's got the same filename as another file rather than just ovewriting or creating a duplicate with a different name.

Is this possible?

Thanks


File Uploading class - how to retrieve filename before uploading file? - El Forum - 10-19-2009

[eluser]pistolPete[/eluser]
I guess you have to access $_FILES directly before using the upload library.
Another option is to extend the upload library.


File Uploading class - how to retrieve filename before uploading file? - El Forum - 10-19-2009

[eluser]tobben[/eluser]
You could maybe use some javascript. Something like (a bit pseudo and real code here..) :

HTML
<input type="file" name="files" id="files" />

Code:
var fileNameToCheck = '';
$(function(){
    $('#files').change(function(){
        fileNameToCheck = $(this).val();
        
        // Do some Ajax-stuff to a PHP script that checks the existens of a given filename/filepath
        // Return value and show a response to the user "OMG! Duplicate file!!!!"
    });
});