php下傳欄位儲存到mysql

來源:互聯網
上載者:User
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 中的 "../" 可能會給後期使用帶來麻煩
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.