0
我有一些PHP代碼來將CSV數據導入到Mysql。它工作正常,但此代碼只適用於名爲trendspry.csv
的特定文件。我想添加代碼,以便我的程序可以從任何目錄中選擇和導入文件。將我選擇的所有CSV文件導入到Mysql使用PHP
我用:
$file = $_FILES['file']['tmp_name'];
但是,當我打印本,它總是顯示:
C:\\xampp\\tmp\\phpABDC
我在做什麼錯?
這是我的全碼:
<?php
if(isset($_POST['submit']))
{
$connect = mysql_connect('127.0.0.1','root','');
if (!$connect) {
die('Could not connect to MySQL: ' . mysql_error());
}
$cid = mysql_select_db('ts_order_track', $connect);
$q = "LOAD DATA INFILE 'trendspry.csv' REPLACE INTO TABLE tsd_orders
FIELDS TERMINATED BY ',' ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(order_id, customer_id, firstname, lastname, email, telephone, mobile, shipping_firstname, shipping_lastname, shipping_mobile, shipping_address_1, shipping_address_2, shipping_city, shipping_zone, shipping_postcode, shipping_country, shipping_method, payment_method, payment_code, weight, date_added, date_modified, import_order_id, sub_total, shipping_charges, tax_charges, total, order_status, courier, awb_code, coupon_amount, coupon_code, product_name, product_sku, product_model, product_quantity, product_price)";
$s = mysql_query($q, $connect);
echo "$q";
echo "File data successfully imported to database!!";
mysql_close($connect);
}
?>
我想改變我的計劃,爲所有我選擇文件。
什麼是abc.csv這裏? –
我不想在代碼中給出文件名。 –
如何定義abc.csv? –