Search the Community
Showing results for tags 'mp4'.
-
Hey everyone! I have a question about handling video files. Are there classes available for handling videos? I've found classes to handle images and I was wondering if there is something similar for videos. I'm asking because I want to allow users to upload videos, but I want to reduce their resolution (take up less space). The video is intended to play in a small section on the page, so it doesn't require high resolution. I'll appreciate any help. Thanks!
-
Greetings all, So I'm trying to set up a video upload page and I can't seem to get it to upload the video. Here's the script. <?php //Start the Session. session_start(); //Set variable for page title prior to loading header which needs variable. $pagetitle = 'Home Page'; //Set variable for css file prior to loading header which needs variable. $navstyle = 'includes/styles/responsivemobilemenu.css'; //Set variable for css file prior to loading header which needs variable. $pagestyle = 'includes/styles/firstlevel.css'; //Set variable for responsive css prior to loading header which needs variable. $pageboiler = 'includes/styles/boilerplate.css'; //Add in header. include ('includes/header.php'); //Requires the database connection script. require ('masters/connect.php'); ?> <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Select an mp4 video file:</legend> <br/> <label for="file">Select a video: </label><input type="file" name="upload" /> <br/> <label for="vidname">Video Name: </label><input type="text" name="vidname" size="25" maxlength="25" value="<?php if(isset($_POST['vidname'])) echo $_POST['vidname'];?>"/> <p><b>Video Description</b></p> <textarea name="viddesc" cols="40" rows="10" maxlength="255"> <?php if(isset($_POST['viddesc'])) echo $_POST['viddesc'];?></textarea> <br/> <div class="buttonHolder"> <br/> <input type="submit" name="submit" value="Begin Upload" /> </div> <br/> </fieldset> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); /* // Check that video file is selected and mp4. if (!isset($_FILES['upload'])) { $errors[] = 'You forgot to select a video for upload.'; } else { $allowed = array("video/mpeg"); if (in_array($_FILES['upload']['type'], $allowed)) { // Get extension to variable. (Added this in case I want to allow other formats in future.) $oldvidname = $_FILES['upload']['name']; $ext = substr($oldvidname,strpos($oldvidname, '.')); } else { $errors[] = 'The file you selected is not an mp4!'; } } */ // Check for a video name: if (empty($_POST['vidname'])) { $errors[] = 'You forgot to enter a name for your video.'; } else { $vidname = mysqli_real_escape_string($connect, trim($_POST['vidname'])); $vidnamecheck = "SELECT * from videofiles WHERE vidname='$vidname'"; $vidresult = mysqli_query($connect,$vidnamecheck); $resultvidcheck = mysqli_num_rows($vidresult); if ($resultvidcheck > 0){ // If vid name exists display message. $errors[] = 'The video name you entered is already being used!';} } // Check for a video description. if (empty($_POST['viddesc'])) { $errors[] = 'You forgot to give the video a description!'; } else { $viddesc = mysqli_real_escape_string($connect, trim($_POST['viddesc'])); } // If no errors upload video and add to database, else report errors. if (empty($errors)) { // Upload Script Begin $oldvidname = $_FILES['upload']['name']; $ext = substr($oldvidname,strpos($oldvidname, '.')); $newviddest = 'videos/' . $vidname . $ext; $newvidname = $vidname . $ext; move_uploaded_file($_FILES['upload']['tmp_name'], $newviddest); // Display success messaage. echo "<p class='message'>Your video has uploaded successfully.</p>"; $query = "INSERT INTO videofiles (vidname, viddesc) VALUES ('$newvidname','$viddesc')"; if (!mysqli_query($connect,$query)){ die('Error: ' . mysqli_error($connect)); } // Close database connection. mysqli_close($connect); // Delete the file if it still exists: if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) ) { unlink ($_FILES['upload']['tmp_name']); } } else { echo '<div id="errorbox">'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; echo '</div>'; } } ?> <?php include ('includes/footer.php'); ?> Ignore the validation check for the file selection. I'm having issues there as well and I commented it out. I plan to take a look at that once I can get the file to even upload. The script adds the fields into the database just fine but the video doesn't upload to the videos folder. Any help is greatly appreciated. Best Regards, Nightasy