Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add($data,$portfolioId,$file=[]){
- $title = $data['title'];
- $url = $data['url'];
- $description = $data['description'];
- $designer = $data['designer'];
- $skill = $data['skill'];
- $date = $data['date'];
- $customer = $data['customer'];
- $link = $data['link'];
- if ($portfolioId == ''){
- $sql = "insert into tbl_portfolio (title,url,description,designer,skill,date,customer,link,img) VALUES (?,?,?,?,?,?,?,?,?)";
- $values = [$title,$url,$description,$designer,$skill, $date, $customer, $link,$newName];
- $this->doQuery($sql,$values);
- $portfolioId = parent::$conn->lastInsertId();
- mkdir('../public/upload/portfolio/'.$portfolioId);
- }
- else{
- $sql = "update tbl_portfolio set title=?,url=?,description=?,designer=?,skill=?,date=?,customer=?,link=? where id=?";
- $values = [$title,$url,$description,$designer,$skill, $date, $customer, $link,$portfolioId];
- $this->doQuery($sql,$values);
- }
- //Upload Start
- if (isset($_FILES['image'])) {
- $file = $_FILES['image'];
- $fileName = $file['name'];
- $fileTmp = $file['tmp_name'];
- $fileSize = $file['size'];
- $target = '../public/upload/portfolio/'.$portfolioId.'/';
- $allowedExts = array("gif", "jpeg", "jpg", "png", "PNG");
- $temp = explode(".", $fileName);
- $extension = end($temp);
- $fileType = @exif_imagetype($fileTmp);
- $allowed = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG);
- /*if (!in_array($extension, $allowedExts)) {
- echo "فرمت عکس غیر مجاز می باشد ";
- }
- else*/if ($fileSize > (2*1024*1024)) {
- echo " سایز عکس زیاد است";
- }
- elseif ((
- (!$file['type'] == "image/gif")
- || (!$file['type'] == "image/jpeg")
- || (!$file['type'] == "image/jpg")
- || (!$file['type'] == "image/png"))) {
- echo " فایل آپلود شده عکس نیست ";
- }
- elseif (!in_array($fileType, $allowed)) {
- echo "فایل ناشناخنه است";
- }
- else {
- $newName = md5(time()).$fileName;
- move_uploaded_file($fileTmp, $target . $newName);
- }
- }
- //Upload End
- header('location:'.adminURL.'portfolio');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement