php上傳圖片

來源:互聯網
上載者:User

標籤:

$size = 2048;//圖片大小限制,Kb        if ((($_FILES["touxiang"]["type"] == "image/png")                || ($_FILES["touxiang"]["type"] == "image/jpeg")                || ($_FILES["touxiang"]["type"] == "image/jpg")                || ($_FILES["touxiang"]["type"] == "image/pjpeg"))                && (($_FILES["touxiang"]["size"]/1024)< $size))        {            if ($_FILES["touxiang"]["error"] > 0)            {                //發生錯誤            }            else            {                $lujing = $_SERVER[‘DOCUMENT_ROOT‘]."\\upfiles\\touxiang\\";//擷取項目根目錄,然後拼接一個路徑,這是windows系統的路徑                $hz = explode(".",$_FILES["touxiang"]["name"]);                $wenjianming = time().rand(999,9999).".".$hz[count($hz)-1];//產生一個隨機檔案名稱,加尾碼                if(($_POST[‘id‘]*1)<=0){die;}//這是其他資料的判斷,無關圖片上傳                if (file_exists($lujing.$wenjianming)){//判斷是否存在該圖片}                else                {
            //這個函數就是將臨時檔案中的圖片移動到你指定的路徑,使用str_replace是為了把路徑調整正確 $isok = move_uploaded_file(str_replace(‘\\\\‘, ‘\\‘, $_FILES[‘touxiang‘][‘tmp_name‘]), $lujing.$wenjianming); if($isok){//如果成功了 include(‘./app/database.config.php‘); $con = mysql_connect($_db_config["host"],$_db_config["user"],$_db_config["pass"]); if (!$con) { die(‘Could not connect: ‘ . mysql_error()); } mysql_select_db($_db_config["data"], $con); $sel = "update ".$_db_config["prefix"]."user set touxiang=‘upfiles/touxiang/".$wenjianming."‘ where id=".$_POST[‘id‘]; mysql_query($sel); echo ‘<textarea>upfiles/touxiang/‘.$wenjianming."</textarea>"; } } } }

這個是配合無重新整理上傳圖片(就是html裡面有個iframe,提交到iframe造成無重新整理假象的那種方式,所以輸出了一片路徑,在html裡面能夠擷取到圖片路徑,能夠即時修改顯示的圖片)

php上傳圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.