原生上传图片方法

  //上传封面图方法
            case 'uploadthumb';
//                var_dump($_FILES);
//                var_dump($_POST);exit;
                $suffix = strrchr($_FILES['file']['name'],".");
                if ((($_FILES["file"]["type"] == "image/gif")
                        || ($_FILES["file"]["type"] == "image/jpeg")
                        || ($_FILES["file"]["type"] == "image/jpg")
                        || ($_FILES["file"]["type"] == "image/png")
                        || ($_FILES["file"]["type"] == "image/gif")
                    || ($_FILES["file"]["type"] == "image/pjpeg"))
                    && ($_FILES["file"]["size"] < 9000000))
                {
                    if ($_FILES["file"]["error"] > 0)
                    {
                        echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $finalimg = time(); move_uploaded_file($_FILES["file"]["tmp_name"], "admin/img/" . $finalimg.$suffix); // echo "Stored in: " . "video4/admin/img/" . $finalimg.$suffix; $thumburl = "admin/img/" . $finalimg.$suffix; // var_dump($_POST); $linkurl = $_POST['linkurl']; $videourl = $_POST['videourl']; $title = $_POST['title']; $discription = $_POST['discription']; $pid = intval($_POST['category']); echo $pid; $addtime = time(); $res = $db -> query( " INSERT INTO `ttf_videos` (`videourl`,`thumburl`,`title`,`discription`,`addtime`,`pid`) VALUES ('$videourl','$thumburl','$title','$discription','$addtime','$pid') " ); // var_dump($res);exit; if($res){ echo ""; }else{ echo ""; } } } } else { echo "Invalid file"; } break;

你可能感兴趣的:(PHP)