php上傳欄位儲存到mysql
PHP code
if($dsql->ExecuteNoneQuery($sql)) { //檔案儲存體路徑 $file_path="../upload/"; //664許可權為檔案屬主和屬組使用者可讀和寫,其他使用者唯讀 if(is_dir($file_path)!=TRUE) mkdir($file_path,0664); //定義允許上傳的檔案擴充 $ext_arr = array("gif", "jpg", "jpeg", "png", "bmp", "txt", "zip", "rar"); //獲得副檔名 $temp_arr = explode(".", $_FILES["photo"]["name"]); $file_ext = array_pop($temp_arr); $file_ext = trim($file_ext); $file_ext = strtolower($file_ext); //擷取上傳檔案的資訊賦給變數 $upfile = $_FILES['photo']; $photo = $upfile; //以時間戳記重新命名檔案 $new_name = time().".".$file_ext; //將檔案移動到儲存目錄下 move_uploaded_file($_FILES["photo"]["tmp_name"],"$file_path" . $new_name); //向資料表寫入檔案儲存體資訊以便管理 foreach($Items as $key=>$val) { $val['price'] = str_replace(",","",$val['price']); $dsql->ExecuteNoneQuery("INSERT INTO `#@__shops_products` (`aid`,`oid`,`userid`,`title`,`price`,`buynum`) VALUES ('$val[id]','$OrdersId','$userid','$val[title]','$val[price]','$val[buynum]');"); } $sql = "INSERT INTO `#@__shops_userinfo` (`userid`,`oid`,`consignee`,`address`,`zip`,`tel`,`email`,`qq`,`cphm`,`t1`,`t2`,`period`,`des`,`dabh`,`photo`,`scanning`) VALUES ('$userid','$OrdersId','$postname','$address','$zip','$tel','$email','$qq','$cphm','$t1','$t2','$period','$des','$dabh','$photo','$scanning'); "; $dsql->ExecuteNoneQuery($sql); } else { ShowMsg("更新訂單時出現錯誤!".$dsql->GetError(),"-1"); exit(); } } else { $sql = "UPDATE `#@__shops_orders` SET `cartcount`='$CartCount',`price`='$priceCount',`ip`='$ip',`stime`='$stime',pid='$pid',paytype='$paytype',dprice='$dprice',priceCount='$lastpriceCount' WHERE oid='$OrdersId' AND userid='$userid' ;"; if($dsql->ExecuteNoneQuery($sql)) { $sql = "UPDATE `#@__shops_userinfo` SET `consignee`='$postname',`address`='$address',`zip`='$zip',`tel`='$tel',`email`='$email',`qq`='$qq',`cphm`='$cphm',`t1`='$t1',`t2`='$t2',`period`='$period',`des`='$des',`dabh`='$dabh',`photo`='$photo',`scanning`='$scanning' WHERE oid='$OrdersId';"; $dsql->ExecuteNoneQuery($sql); } else { echo $dsql->GetError(); exit; } unset($sql); }
為什麼表單提交後photo欄位顯示成Array而不是圖片上傳後的路徑?檔案是能上傳提交上去的,那個地方出了問題還請高手賜教!!!!
------解決方案--------------------
與欄位 photo 對應的是變數 $photo
而
$photo = $upfile;
且
$upfile = $_FILES['photo'];
是一個數組
你應該將 $file_path . $new_name 存入 photo 欄位
但 $file_path 中的 "../" 可能會給後期使用帶來麻煩