PHP: Check if file exists before truncate table : <p>Can someone please help me to make this script check if the file exists, before it truncate the table.
If filename not exists, I want to stop the import.</p>

<pre><code>&lt;?php
//set the connection variables
$hostname = "host";
$username = "username";
$password = "pass";
$database = "database";
$filename = "filename.csv";

//connect to mysql database
$connection = mysqli_connect($hostname, $username, $password, $database) or die("Error " . mysqli_error($connection));

mysqli_query($connection, "TRUNCATE TABLE `my_tablename`");

// open the csv file
$fp = fopen($filename,"r");

//parse the csv file row by row
while(($row = fgetcsv($fp,"500",",")) != FALSE)
{
    //insert csv data into mysql table
    $sql = "INSERT INTO Pristabell (Produkt, Pris, Rabattkr, Rabattprosent, Lagerstatus, Butikk, TAGS) VALUES('" . implode("','",$row) . "')";
    if(!mysqli_query($connection, $sql))
    {
        die('Error : ' . mysqli_error($conection));
    }
}
fclose($fp);

//close the db connection
mysqli_close($connection);

?&gt;
</code></pre>

<p>Thanks :-)</p>
