Hi guys. I’m pretty new to php so any help would be appreciated.
I am working on a file upload system on a website which allows the users to upload an excel file with the data then being stored in a phpmyadmin database.
I have been stuck on this error for a few days and I am starting to lose hope.
[php]
if ( isset($_FILES["orderImp"]))
{
$fileName = pathinfo($_FILES['orderImp']['name'], PATHINFO_FILENAME);
$now = date("d_m_y");
$fileName = $fileName.".xlsx" ;
//if file already exists
// echo $fileName;
if (file_exists("../Upload/" . $fileName))
{
unlink("../Upload/".$fileName);
}
$storagename = $fileName;
move_uploaded_file($_FILES["orderImp"]["tmp_name"], $_SERVER["DOCUMENT_ROOT"] .'/OnlineOrder/Upload/' . $storagename);
if ( $file = fopen( $_SERVER["DOCUMENT_ROOT"] .'/OnlineOrder/Upload/' . $storagename , "r" ) or die("Can't open file !") )
{
$firstline = fgets ($file );
//Gets the number of fields, in CSV-files the names of the fields are mostly given in the first line
$num = strlen($firstline) - strlen(str_replace(";", "", $firstline));
//save the different fields of the firstline in an array called fields
$fields = array();
$fields = explode( ";", $firstline, ($num+1) );
$line = array();
$i = 0;
$dsatz=array();
while ( $line[$i] = fgets ($file) )
{
$dsatz[$i] = array();
$dsatz[$i] = explode( ";", $line[$i], ($num+1) );
$i++;
}
$lNum = 1;
foreach ($dsatz as $key => $number)
{
$code = "";
$qty= 0;
$inst = "";
foreach ($number as $k => $content)
{
if(trim($fields[$k]) == "Numero")
{
$custOrderNo = $content;
}
}
}
}
}
[/php]
This code gives me the following warning
Warning: fopen(D:/XAMPP/htdocs/OnlineOrder/Upload/file1.xlsx): failed to open stream: No such file or directory in D:\XAMPP\htdocs\OnlineOrder\XLSXReader-master\sample.php on line 27
Can’t open file !
Line 27 is
if ( $file = fopen( $_SERVER["DOCUMENT_ROOT"] .'/OnlineOrder/Upload/' . $storagename , "r" ) or die("Can't open file !") )
I hope the format is right as this is my first post. Any help/leads/pointers would be greatly appreciated. Thanks in advance.