我想通過我的PHP上傳文件,我的代碼是這樣的:上傳文件(ID名)
$hasil = mysql_query("select ID from userownfile order by ID DESC");
$dt = mysql_fetch_array($hasil);
$old_id = substr($dt['ID'],2);
$newId = $old_id[0] + 1;
$base = $_REQUEST['image'];
$filename = $newId . ".jpg";
$buffer = base64_decode($base);
$path = "img/" . $filename . ".jpg";
$handle = fopen($path, 'wb');
$numbytes = fwrite($handle, $buffer);
fclose($handle);
$conn = mysql_connect("localhost","root","");
mysql_select_db("db_bloodglucose");
$sql = "insert into userownfile(ID, file) values('" . $newId . "','" . $path . "')";
$r = mysql_query($sql);
在第一次上傳,我已經贏得成功上傳的文件哪個名稱1 .jpg,但是當我想上傳第二次等,它沒有顯示在我的數據庫上,它不斷顯示1.jpg,我想知道爲什麼數字沒有增加..任何人都可以幫助我?謝謝,我已經
之前更改我的代碼是這樣的:
<?php
$hasil = mysql_query("select ID from userownfile order by ID DESC");
$dt = mysql_fetch_array($hasil);
$old_id = substr($dt['ID'],2);
$newId = mysql_insert_id() + 1;
$base = $_REQUEST['image'];
$filename = $newId . ".jpg";
$buffer=base64_decode($base);
$path = "img/".$filename.".jpg";
$handle = fopen($path, 'wb');
$numbytes = fwrite($handle, $buffer);
fclose($handle);
$conn=mysql_connect("localhost","root","");
mysql_select_db("db_bloodglucose");
$sql = "insert into userownfile(ID, file) values('" . $newId . "','" .
$path . "')";
$r=mysql_query($sql);
?>
但是,它保持貼着1,數量不增加,任何人都可以幫我嗎?
在第一次嘗試時是否確實會插入數據庫? –
@Handy看到我的問題上面 - 什麼都插入到數據庫中? –
@pekka,第一個插入我的數據庫,1.jpg,但是當我再次嘗試第二個等,它沒有工作......我已將我的ID設置爲「無自動增量」 – Handy