I'm having an strange issue, while importing the .xlsx file in to the mysql database using php script.
The excel files are being generated from another oracle db server, and are being copied on my server. The script is not inserting any record until and unless, I manually
- open the file,
- Save it, and
- close it.
This is pretty strange, because I'm not making any change in the file, no change at all. I've already compared the file permissions, before and after saving the files and there is no change.
For the excel files, I'm creating on my current server are working fine without any hassle.
DB File
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else{
echo "Connection Made Succesfully !!!";
}
?>
CODE Sample
<?php
include 'db.php';
if (isset($_FILES['file'])) {
IF($_POST["TotalCol"] && $_POST["TableName"])
{
require_once "simplexlsx.class.php";
$xlsx = new SimpleXLSX( $_FILES['file']['tmp_name'] );
list($cols, $rows) = $xlsx->dimension();
foreach( $xlsx->rows() as $k => $r)
{ // loop through excel worksheet
$sub = mysql_escape_string($r[0]);
for ($x = 1; $x < $_POST["TotalCol"]; $x++) {
$sub .= "','".mysql_escape_string($r[$x]);
}
//$sub = mysql_escape_string($r[0])."','" . mysql_escape_string($r[1]);
//$q = "insert into test2 value('" . mysql_escape_string($r[0])."','" . mysql_escape_string($r[1])."','" . mysql_escape_string($r[2]) . "');";
$q = "insert into ".$_POST["TableName"]." value('" . $sub . "');"
if ($conn->query($q) === TRUE) {
echo "New record created successfully";
} else {
echo "<br>// Error: " . $sql . "<br>" . $conn->error . "<br>";
}
} // IF ENDS HERE
}
}
?>
<h1>Upload</h1>
<form method="post" enctype="multipart/form-data">
*.XLSX <input type="file" name="file" /></br><input type="Text" name="TableName" class="TableName" placeholder="TableName" /></br><input type="Text" name="TotalCol" class="TotalCol" placeholder="Total Columns" /> <input type="submit" value="Insert" />
</form>
And I'm using the simplexlsx.class.php Class from here