I am a PHP beginner writing a program to upload .csv files to a webpage. When testing my program, I have been using a file called Partitions.csv. However, now I need to upload files that are named differently and when I try to do this, my code will not accept the file. This is my HTML code where I upload my file.
<form action="uploader.v1.2.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload" accept=".csv"/>
<input type="submit" value="Upload File" name="submit" />
</form>
This is my PHP code for accepting the file.
$sheetData = array();
if (($handle = fopen($_FILES["fileToUpload"]["name"], "r")) !== FALSE)
{
while (($dat = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$sheetData[] = $dat;
}
fclose($handle);
}
else
{
echo '<script language="javascript">';
echo 'alert("Error Uploading File")';
echo '</script>';
}
Could anyone tell me why I cannot upload files that have different file names. Any help would be appreciated. Just to reiterate, I am a PHP beginner