Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:32:38+00:00 2026-06-17T21:32:38+00:00

Below is my code where it uploads a file into a server and stores

  • 0

Below is my code where it uploads a file into a server and stores the names of each uploaded file into the db:

<?php

 // connect to the database
 include('connect.php');

  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
  }


    if ($_FILES['fileVideo']['error'] === UPLOAD_ERR_OK) { 

$result = 0;


if( file_exists("VideoFiles/".$_FILES['fileVideo']['name'])) {
    $parts = explode(".",$_FILES['fileVideo']['name']);
    $ext = array_pop($parts);
    $base = implode(".",$parts);
    $n = 2;

    while( file_exists("VideoFiles/".$base."_".$n.".".$ext)) $n++;
    $_FILES['fileVideo']['name'] = $base."_".$n.".".$ext;

    move_uploaded_file($_FILES["fileVideo"]["tmp_name"],
    "VideoFiles/" . $_FILES["fileVideo"]["name"]);
    $result = 1;

}
    else
      {
      move_uploaded_file($_FILES["fileVideo"]["tmp_name"],
      "VideoFiles/" . $_FILES["fileVideo"]["name"]);
      $result = 1;
  }

    $videosql = "INSERT INTO Video (VideoFile) 
    VALUES (?)";

        if (!$insert = $mysqli->prepare($videosql)) {
      // Handle errors with prepare operation here
    }

    //Assign the variable
$vid = 'VideoFiles/'.$_FILES['fileVideo']['name'];

            //Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s",$vid);

 $insert->execute();
 $id = $mysqli->insert_id;

        if ($insert->errno) {
          // Handle query error here
        }

        $insert->close();     

        }else{
  echo "Upload was not successful";   
  }

?>

 <script language="javascript" type="text/javascript">
 window.top.stopVideoUpload(<?php echo $result; ?>,'<?php echo $id; ?>', '<?php echo $_FILES['fileVideo']['name']; ?>');
 </script>  

</body>
</html>

Now I am using a jwplayer and it requires video files to match video formats on this page:

http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12539/supported-video-and-audio-formats/

So I need to be able to encode files automatically on the server when the file is uploaded into the server. I do not want the user to try and encode a video file manually by themseleves, I want it done automatically. But my question is how can I get automatic server side file encoding to work?

I have a demo showing how a video file is uploaded: DEMO

To use Demo:

  1. Click on Add Question button and file input will appear in table

  2. Click on upload straightaway and you will see a simple validation stating which video file format are allowed (this is simply done by checking video file extension)

  3. Browse for a video file, select and then click on Upload and wait for upload to finish (I recommend a short video file for saving time). When file is uploaded it will display success message and video file is uploaded into server,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:32:39+00:00Added an answer on June 17, 2026 at 9:32 pm

    Many ways of doing that. The easiest and fastest in terms of programmer time is to use ffmpeg to directly encode the thing into something useable, right in your upload script (use exec or system to do so).

    This imposes some problems though: your browser might drop in a timeout when the server is too busy processing the request. Also, you cannot really spread the load.

    So, after the upload is succesfull, you call ffmpeg:

    exec("ffmpeg -i $vid -vcodec libx264 -vpre default -crf 21 ".
                          "-acodec libfaac -ab 128k $vid-transcoded.mp4");
    

    You will have to refer to the ffmpeg website for all options (there are a lot of them). Also, jwplayer is quite popular, so there should be many resources on how to transcode it.

    So, another solution is to have the server upload files in a to_be_processed directory and have a background process (cronjob perhaps?) to process all files in that dir. That way, the browser request is done when the upload is done and you are in full control of processing resources. This, however, takes a considerate amount of programmer time. You will have to create the processing job, as well as do some administration work to let the user know how far the processing is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the code below that uploads a file and inserts data into
Below code uploads file on the FTP server public class UploadFile { static ResourceBundle
I am using the code below that uploads a file and inserts data into
Below is part of the code where it uploads a file (fileImage) into a
I have a mysqli code below where it uploads a file and insert data
How do I browse to upload a file using Dojo? See the code below:
I am using below code to upload excel and INSERT in mysql in php
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
I am trying to upload an image path into database and save file in
I am trying to import a .csv file into my database. I am able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.