Referencing a movie file in Mysql using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
idnoble
Forum Commoner
Posts: 28
Joined: Wed Mar 31, 2004 4:09 am

Referencing a movie file in Mysql using PHP

Post by idnoble »

Hello
I'm trying to reference a movie trailer in MySQL using PHP, i don't want to upload the movie directly into Mysql as it is big so I'm keeping it in an external file. Anyway I've written my PHP script and an HTML to accompany it
but each time I submit the form and it got passed on to the script for processing the script screen, gives me no feedback, no error message or upload succesful message just a blank screen, and I tried to see if the file was succesfully referenced in MySQL but the table was blank meaning it wasn't succesful, can anyone please help.

Here is the PHP script

Code: Select all

<?php

$session = mysql_connect("localhost", "root", "platinum");
mysql_select_db("xplosive");

$fd = fopen($form_data, "rb")or die(mysql_error());
$data = addslashes (fread($fd, filesize($form_data)));

$query = "INSERT INTO trailer(Clip, filename, filesize, filetype)".
          "VALUES ('$data', '$form_data_name', '$form_data_size', '$form_data_type')";

$result = mysql_query($query);
if (!$result )
{
  echo ("<p>Error performing INSERT: " .mysql_error(). "</p>" );
}
else
{
  $Id = mysql_insert_id();
  print "<p> Upload succesful. Trailer ID: <B>$Id</B>";
}
fclose($fd);
mysql_close($session);
?>
and my HTML code

<html>
<head>
<title>Add Trailer</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"></head>
<body background="../Graphics/backgd.gif">
<div align="center">
<p align="center"<img src="D:\phpWeb\Graphics\Xlogo.png" width="252" height="152"></p>
<h1>Upload trailer to the database</h1>
</div>
<form method="post" action="trailer.php" enctype="multipart/form-data">
<p style="font-size: 15pt; color:black;font-syle: sylfaen">Trailer:<BR>
<input type="file" name="form_data" size="40">
<input type="hidden" name="max_file_size" value="1073741824">
<BR>
<BR>
<input type="submit" name="submit" value="Upload"</form>
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

"rb" is not a valid fopen() arguement:

http://us3.php.net/fopen
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

"rb" is not a valid fopen() arguement:

http://us3.php.net/fopen
idnoble
Forum Commoner
Posts: 28
Joined: Wed Mar 31, 2004 4:09 am

Post by idnoble »

Hello thanx
I've changed it to "r", but still nothing
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

idnoble wrote:Hello thanx
I've changed it to "r", but still nothing
If you don't write the file data, just the information about it, does that record go in? In other words, change this:

$query = "INSERT INTO trailer(Clip, filename, filesize, filetype)".
"VALUES '$data', '$form_data_name', '$form_data_size', '$form_data_type')";

to this:

$query = "INSERT INTO trailer(filename, filesize, filetype)".
"VALUES '$form_data_name', '$form_data_size', '$form_data_type')";

And see if that works. If it does, then you need to chase why the data file is not wanting to go in. But if it doesn't, then you need to chase why that is the case. This will help you divide and conquer the problem.

Hope it helps.
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

'rb' *IS* a valid fopen argument... it's read-mode with binary compatibility... consult the manual.
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post by Pozor »

Hello,

look at this:

Code: Select all

<?php
$query = "INSERT INTO trailer(Clip, filename, filesize, filetype)". 
          "VALUES ('$data', '$form_data_name', '$form_data_size', '$form_data_type')"; 

// change to:
$query = "INSERT INTO trailer (Clip, filename, filesize, filetype)". 
          " VALUES ('$data', '$form_data_name', '$form_data_size', '$form_data_type')"; 
?>
greez Pozor
Post Reply