0

I got this problem when I try to do form upload for video using oop PHP (Error code: 1) and I don't know how to fix it

<?php 
class VideoProcessor {

    private $con;
    private $sizeLimit = 500000000;
    private $allowedTypes = array("mp4", "flv", "webm", "mkv", "vob", "ogv", "ogg", "avi", "wmv", "mov", "mpeg", "mpg");

    public function __construct($con) {
        $this->con = $con;
    }



    public function upload($videoUploadData) {

        $targetDir = "uploads/videos/";

        $videoData = $videoUploadData->videoDataArray;

        $tempFilePath = $targetDir . uniqid() . basename($videoData["name"]);

        $tempFilePath = str_replace(" ", "_", $tempFilePath);

        $isValidData = $this->processData($videoData, $tempFilePath);

        if(!$isValidData) { 
            return false;
        }

        if(move_uploaded_file($videoData["tmp_name"], $tempFilePath)) {
            echo "File moved successfully";
        }


    }
    private function processData($videoData, $filePath) {

        $videoType = pathinfo($filePath, PATHINFO_EXTENSION);


        if (!$this->isValidSize($videoData)) {
            echo "File too large. Can't be more Than " . $this->sizeLimit . " bytes";
            return false;
        }


        else if(!$this->isValidType($videoType)) {
            echo "Invalid file type";
            return false;
        }

        else if($this->hasError($videoData)) {
            echo "Error code: " . $videoData["error"];
            return false;
        }

        return true;
    }

    private function isValidSize($data) {
        return $data["size"] <= $this->sizeLimit;
    }

    private function isValidType($type) {
        $lowercased = strtolower($type);
        return in_array($lowercased, $this->allowedTypes);
    }

    private function hasError($data) {
        return $data["error"] != 0;
    }
}
?>
Rahul
  • 18,271
  • 7
  • 41
  • 60
  • 2
    `Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.` So either smaller files are needed, or you need to increase the max filesize directive. – Jonnix Aug 27 '19 at 10:44
  • the file size is just 5MB so how it is exceeds the upload_max_filesize ? – Zaidoun Mohammed Aug 27 '19 at 11:09
  • Well, the default upload_max_filesize is 2MB, so.... that's how :) – Jonnix Aug 27 '19 at 11:14
  • can you tell me how to change it because iam just Beginner so i didn't know how to change it and I will appreciate this – Zaidoun Mohammed Aug 27 '19 at 11:20
  • Sure, have a read of https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size – Jonnix Aug 27 '19 at 11:22
  • Possible duplicate of [Change the maximum upload file size](https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size) – Dave Aug 27 '19 at 11:46

0 Answers0