Jump to content

[SOLVED] php upload script not writing to database correctly


bruckerrlb

Recommended Posts

Hello all,

 

I have been wracking my brains with this for a while now, I am uploading a file, the file uploads, then it writes to a database, that is all good, but one of my fields in the database is the path. I am trying to get the name of the file inserted into the database, and now it's not going in, nothing is going in the path field, only the primary id, and another field I have set up.

<?php

error_reporting(1);

$filepath = getcwd()."/files/";
//This is what I thought was correct, how to get the name of the file, but it's not showing up in my //database. 
$uploadfile = $filepath . basename($_FILES['userfile']['name']);
if(!file_exists($filepath)) {
mkdir($filepath,0777);
}
chmod($filepath,0777);

if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $filepath.$_FILES['Filedata']['name'])){
chmod($filepath.$_FILES['Filedata']['name'], 0777);

$link = mysql_connect("localhost","a username","a password");
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("thedb");
if(!$db) {
	die("Unable to select db");
}
$query = "INSERT INTO video
	(id, path, page)
	VALUES (0, '$uploadfile', 'livevideo')";
	if (@mysql_query ($query)) {
	print 'Successfully Added!';
	}
	mysql_close();



}


?>

 

So the following code returns me the entire path minus the name of the file, just the path to the folder that the file is in, and when I use the following as my variable, it returns nothing

$uploadfile = $_FILES['userfile']['name'];

 

I was reading the php site, and the first way is how they have there code set up, but it doesn't seem to be working for me, or they are trying to do something different, does anyone have any tips?

 

FYI I figured this out, see code below for explanation

$uploadfile = $_FILES['Filedata']['name'];

 

where filedata is, it has to be the name on the form uploader, I was using userfile, which is the <i>example</i> on the php site!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.