Forum Moderators: coopster

Message Too Old, No Replies

Problem with upload script

         

Awful newbie

9:39 pm on May 1, 2007 (gmt 0)

10+ Year Member



I try to make a upload script where I can upload documents, categorize them, and add metadata as the submitter, an url related to the document, a checkbox to confirm the data and add the data the document was uploaded. Everything, included the file, are supposed to rest in the MySQL db.
But my script won't work, there is something wrong with the file-upload function. Please, are there anyone with any idea?

<?php

//variables from form post (uploaded file 'file', category 'category', submitter 'submitter', the_url, 'the url related to the file', checkbox 'checkbox-has to be cheked in order to send the form data', thedate 'the date the form is prosessed'

$file_Name = $_FILES['file']['name'];
$file_Size = $_FILES['file']['size'];
$file_Temp = $_FILES['file']['tmp_name'];
$file_Mime_Type = $_FILES['file']['type'];
$category = addslashes($_POST['category']);
$submitter = addslashes($_POST['submitter']);
$the_url = addslashes($_POST['the_url']);
$checkbox = addslashes($_POST['checkbox']);
$thedate = addslashes($_POST['thedate']);

// Validation
if (strlen($file) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please select file</font></p>");
}

if (strlen($category) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please select category</font></p>");
}

if (strlen($checkbox) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please check!</font></p>");
}

//connecting to db

$username="username";
$password="password";
$database="database";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

//insert data

$query = "INSERT INTO uploaded_files VALUES ('','$file','$category','$submitter','$the_url','$checkbox','$the_date')";
mysql_query($query);

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Success uploading</font></p>");

mysql_close();
?>

eelixduppy

12:02 am on May 2, 2007 (gmt 0)



You want to place the file into a mysql table?

There is also great documentation on file uploads at php.net. You might want to take a look there, too: [php.net...]

dreamcatcher

7:24 am on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple of other things. Firstly, you are accessing a var that isn`t set. In this case $file. So, for development always set your error reporting level to E_ALL. At the top of your script add this:

error_reporting(E_ALL);

Also, to debug your mysql query, use mysql_error().

mysql_query($query) or die(mysql_error());

You`ll see some error messages when you use these features, but this should help you sort out a few problems.

dc