Empty-handed Upload!
Posted: Tue Aug 16, 2005 3:00 am
I want to check if a user had given an existing file for upload. But the $_FILES['userfile'] array only got the name of the file stripped of its directory.
If the user entered 'C:\documents\report1.xls', then $_FILES['userfile']['name'] only contains 'report1.xls'.
In order to get the complete directory of the file, I added a hidden field to the form to copy the value of file input to it upon for submission.
The filepath hidden field will be sent on $_POST and the rest on $_FILES.
The problem is that all the function (at least, all I know) available for this situation, such as file_exists and is_file, are always returning false even if the file really exists.
Am i missing something here?
How can I check if the file touplaoded exists?
Thanks in advance
If the user entered 'C:\documents\report1.xls', then $_FILES['userfile']['name'] only contains 'report1.xls'.
In order to get the complete directory of the file, I added a hidden field to the form to copy the value of file input to it upon for submission.
Code: Select all
<form ... onsubmit='filepath.value=userfile.value'>
// ...
<input type=hidden name='filepath'>
<input type=file name='userfile'>
// ...
</form>The problem is that all the function (at least, all I know) available for this situation, such as file_exists and is_file, are always returning false even if the file really exists.
Code: Select all
$filepath = $_POST['filepath'];
if(file_exists($filepath)){
// .... or
if(is_file($filepath)){
// always returns trueHow can I check if the file touplaoded exists?
Thanks in advance