我目前使用的是使用Solaris作爲服務器的HTML,MySql和PHP的組合。我在MySql上創建了這些表,並且需要使用Html將文件從我的PC桌面上傳到服務器的文件夾。如何使用選擇的文本文件並上傳到solaris?
第一個按鈕用於選擇文件 第二個按鈕用於將數據加載到總部數據庫 第三個按鈕用於跳轉到另一個php文件。
我得到2個查詢,首先,使用選定文本文件中的數據加載到數據庫的代碼是什麼。其次,如何用第三個按鈕跳轉到另一個目錄?
<h2> Upload HQ WareHouse</h2>
//upload file function
<form method ="post" action="checkTransaction.php" enctype="multipart/form-data">
<input type="file" name ="datatxtfile" id ="datatxtfile">
<input type="submit" value= "Click here to Upload The Transaction's File into the Database">
</form>
<br>
<input type="button" name="a" value= "Click here to return " onclick ="hist()">
</body>
//PHP code to explode
<?php
$file = file_get_contents("Inventory_1000.txt");
//var_dump($file);
$lines = explode("\n",$file);
print_r($lines); print line
foreach($lines as $index => $line) {
$data = explode(":", $line);
mysql_query("INSERT INTO wareHouse (
productName, categoty, manufacturer, barcode, buyingPrice, currentStock, minimumStock)
VALUES
'". $data[0] ."',
'". $data[1] . "',
'". $data[2] ."',
'". $data[3] . "',
'". $data[4] ."',
'". $data[5] . "',
'". $data[6] . "'
)") or die(mysql_error());
}
?>
=========================================== ====
修訂
爲了澄清,
我想在一個目錄通過PHP,HTML在PC上選擇位置的動態.txt文件並加載長達一個在線數據庫solaris上的mySQL,所以我不能使用語法.txt加載到數據庫中。
底部只是一個示例代碼,我如何在mySQL上使用示例.txt文件,因爲我不知道如何選擇動態.txt。
因此,操作是如下: 1)第一個按鈕將選擇從目錄.txt文件
2)第二按鈕將被上傳數據到MySQL,假設.txt文件是兼容和不 損壞的
3)第三個按鈕允許用戶上傳文件做
請問我如何完成它,因爲我打算建立一個動態的.txt文件名後返回其他頁面?
http://www.w3schools.com/php/php_file_upload.asp – Drew
如陳述[引進](http://www.php.net/manual/en/intro.mysql.php)到'mysql_ *'函數的PHP手冊一章:*不推薦使用此擴展來編寫新代碼。相反,無論是[mysqli](http://www.php.net/manual/en/book.mysqli.php)還是[PDO_MySQL](http://www.php.net/manual/en/ref.pdo應該使用-mysql.php)擴展名。另請參閱[MySQL API概述](http://www.php.net/manual/en/mysqlinfo.api.choosing。php)在選擇MySQL API時提供進一步幫助。* – eggyal