Page 1 of 1

Referencing a movie file in Mysql using PHP

Posted: Fri Apr 02, 2004 1:24 pm
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>

Posted: Fri Apr 02, 2004 2:38 pm
by Steveo31
"rb" is not a valid fopen() arguement:

http://us3.php.net/fopen

Posted: Fri Apr 02, 2004 2:40 pm
by Steveo31
"rb" is not a valid fopen() arguement:

http://us3.php.net/fopen

Posted: Fri Apr 02, 2004 3:08 pm
by idnoble
Hello thanx
I've changed it to "r", but still nothing

Posted: Fri Apr 02, 2004 3:31 pm
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.

Posted: Fri Apr 02, 2004 4:10 pm
by EvilWalrus
'rb' *IS* a valid fopen argument... it's read-mode with binary compatibility... consult the manual.

Posted: Fri Apr 02, 2004 5:25 pm
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