中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

php上傳圖片代碼演示

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
表單代碼

<form name="form1" method="post" action="admin_upfile.php" enctype="multipart/form-data">
    <input type="file" name="pic">
    <input type="submit" name="Submit" value="開始上傳" class="button">
</form>

后端php代碼
<?php
                //這里上傳 $upsize判斷上傳文件的大小
                $uppath = "/attached/"; //文件上傳路徑
                //轉(zhuǎn)換根目錄的路徑
                if (strpos($uppath, "/") == 0)
                {
                    $i = 0;
                    $thpath = $_SERVER["SCRIPT_NAME"];
                    $thpath = substr($thpath, 1, strlen($thpath));
                    while (strripos($thpath, "/") !== false)
                    {
                        $thpath = substr($thpath, strpos($thpath, "/") + 1, strlen($thpath));
                        $i = ++$i;
                    }

                    $pp = "";
                    for ($j = 0; $j < $i; ++$j)
                    {
                        $pp .= "../";
                    }

                    $uppaths = $pp . substr($uppath, 1, strlen($thpath));
                }
                $filename = date("y-m-d");
                if (is_dir($uppaths . $filename) != TRUE)
                    mkdir($uppaths . $filename, 0777);

                $f = $_FILES['pic'];

                if ($f["type"] != "image/gif" && $f["type"] != "image/pjpeg" && $f["type"] != "image/jpeg" && $f["type"] != "image/x-png")
                {
                    echo "<script>alert('只能上傳圖片格式的文件');window.close()</script>";
                    return false;
                }

                //獲得文件擴(kuò)展名
                $temp_arr = explode(".", $f["name"]);
                $file_ext = array_pop($temp_arr);
                $file_ext = trim($file_ext);
                $file_ext = strtolower($file_ext);

                //新文件名
                $new_file_name = md5(date("YmdHis")) . '.' . $file_ext;

                echo $dest = $uppaths . $filename . "/" . date("ymdhis") . "_" . $new_file_name; //設(shè)置文件名為日期加上文件名避免重復(fù) 上傳目錄
                echo $dest1 = $uppath . $filename . "/" . date("ymdhis") . "_" . $new_file_name; //設(shè)置文件名為日期加上文件名避免重復(fù)
                $r = move_uploaded_file($f['tmp_name'], $dest);
                ?>

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:php漢字轉(zhuǎn)換成拼音的代碼類

下一篇:python轉(zhuǎn)換字符集