Assistance needed for uploading videos using MySQL database and PHP code

Currently, I am in the process of writing PHP code that will be used to both upload and display a Quicktime .mov file by interacting with MySQL. While I have had success with working on similar tasks involving image formats in the past, this particular circumstance is proving to be challenging. The file upload function seems to be functioning correctly as data is being inserted into the SQL table and the client is able to access the viewvideo.php script. However, there arises an issue when the client attempts to parse the received data as a Quicktime movie, suggesting a potential decoding error along the way. Here are key snippets from the two scripts:

The uploading portion:

$name = $_FILES["file"]["tmp_name"];
$contents = file_get_contents($name);
mysql_query("INSERT INTO videos(id,data,title,description) VALUES($n,'$contents','$title','$description')");

The displaying part:

$x = mysql_query("SELECT data FROM videos WHERE id=$id");
$results = mysql_fetch_array($x);
$data = $results[0];
header("Content-Type: video/quicktime");
echo $data;
exit;

My initial theory is that enclosing '$contents' in single quotes may be causing issues with encoding the string properly. Due to maintenance work on the SQL server currently underway, I am unable to immediately test this hypothesis. Any suggestions or assistance would be greatly appreciated.

Answer №1

Not a good idea to store this in a database. Blobs are typically used for binary data that is smaller than 256KB. Check out more information here.

My recommendation would be to upload the .mov files using an

<input type="file" .../>

and then access them directly via HTTP or stream them from the Server using a player plugin (like Flash, for example).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Passing Parameters Using Axios in Vue.js

Currently, I am utilizing Axios within VueJS to make ajax requests. However, I have encountered an issue when attempting to send these requests. This snippet shows my JavaScript code: axios.post('http://localhost/app/php/search.php', { quer ...

``The background color will dynamically change according to the result of a function

My function named shift_color generates different color codes like "#FF5F74", "#5FFF66", and "#5F8AFF". I am looking to use this output to style a navigation menu background. I have tried the following code: .topnav { background-color: <?php echo shi ...

Using PHP and ffmpeg to upload and store videos on the internet

Currently, my website features a functionality that enables users to upload videos onto it. Following the video uploads, I aim to showcase them via a flash player. One prominent flash player I am aware of is flowplayer; however, if there are better alter ...

Is it possible to showcase dates within input text boxes prior to POSTing the form?

I am currently working on a form that posts to a PHP script by selecting a date range. For a better understanding, you can check out my visual representation here. Before the data is posted, I would like to display the selected dates in empty boxes or inpu ...

Is there a way to make function queries more concise?

Hello, I am trying to optimize this function: function check_email($email){ global $db; $email = sanitize($email); $query = $db->query("SELECT COUNT(*) FROM table1 WHERE Email= '$email' OR SELECT COUNT(*) FROM table2 WHERE Email= ...

Using ajax to send an array to PHP

I have an array named "heart" that is being sent via ajax... var heart = [31,32,33,34,35,36,37,38,39,42,43]; // Sending this data via ajax to php file/ $.ajax({ type: "POST", data:{ 'system': heart }, url: "login-function.php", success: f ...

Newbie Python Programmer: How to Send Selenium WebElement Object to PHP

I am currently exploring the possibility of extracting data from a website and then passing it for use in PHP. After researching various methods, one suggestion that stood out to me was to serialize the Python data before transferring it. However, I seem ...

PHP code to strip subdomain from a URL

Currently, I am using a PHP script to clean URLs from a text file. Below is the code snippet: $file = __DIR__."/url.txt"; $f = fopen($file, "r"); $array1 = array(); while ( $line = fgets($f, 1000) ) { $nl = mb_ ...

Real-time drop down options change depending on selection in another drop down menu

Seeking guidance in the right direction, I am currently working with a file called data.php. Inside this file, I have the following data: $sports_arr = array(); $sports_arr[] = "Basketball"; $sports_arr[] = "Baseball"; $sports_arr[] = "Football"; Additio ...

json success function not being triggered

I am facing an issue with executing the success function in my code while trying to post the value of an input box and retrieve the value of a checked radio button. The objective is to perform a query based on which radio button is checked. Here is the HT ...

Deactivate the button and forms in AngularJS

Hey there, I could really use some assistance with this. I'm puzzled as to why my form and buttons aren't disabling during the file upload process. Any help would be greatly appreciated. Thank you! <div> <form name="formImport" ng-s ...

Localhost is causing issues with Laravel in retrieving webfonts

I was trying to incorporate font-awesome into my Laravel project, but encountered a strange error. When I run the project, the following error appears in the console: GET http://localhost/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.woff2?5 ...

Using PHP to loop through SQL data and convert it to JSON format, mapping information from two tables based on their related IDs

I always wish for your good health. I am currently facing an issue trying to generate a JSON array from 2 tables. Here are the tables I have: Table 1: app_produk_ready Table 2: app_produk_ready_img Below is the PHP code I have written: <?php require_ ...

I'm encountering an issue with the dropify plugin where the data-allowed-file-

While using the dropify library to style file upload elements in my form, I ran into an issue with the data-allowed-file-extensions parameter not working as expected. Despite specifying allowed file extensions like "png jpg jpeg", the validation for input ...

Errors in JSON.parse: which character am I not detecting?

My development environment includes PHP 5.3.5, MySQL Server 5.5.8, and jquery version 1.6. I'm using Ajax to automatically populate a dropdown list of countries, but I keep encountering an error that persists despite trying various solutions. For exa ...

Capturing content from an HTML node and integrating it into VueJS data

<tasks> @foreach ($task as $tasks) <task>{{ $task->name }} [{{ $task->completed }}]</task> @endforeach </tasks> This snippet shows how I display a list of tasks from the database. Here is my Vue component setu ...

What is the best way to transmit a two-dimensional array using ajax?

Here is the process I use to send data to the server: var points = []; var coords = polyline.geometry.getCoordinates(); for (var i = 0; i < coords.length; i++) { var x = (coords[i][0]).toFixed(4); var y = (coords[i][1]).toFixed(4); points[i ...

Tips for utilizing richtextarea with html entities and managing the character limit for storage in a database

When using richtextarea, users can select text and change it to bold or italic. $("#edit2").richtextarea({ toolbar: false }); $("#bold").click(function() { $("#edit2").richtextarea('bold'); }); However, the output is sanitized using htmlenti ...

Error: A SyntaxError was encountered due to a missing closing parenthesis after an argument list while writing JavaScript within PHP code

I'm facing an issue writing JavaScript within PHP code. Here's my script : echo ' <script>'; echo ' $(function(){'; echo ' x = parseInt($("#counter2").val());'; echo ' $("#add_row2").click(function(){&apo ...

What is the best way to iterate through indexed numbers within a stdClass Object?

The desired output that I am attempting to access is as follows: stdClass Object ( [results] => stdClass Object ( [columns] => stdClass Object ( [name] => Name [id] => ...