Jump to content

[SOLVED] php upload script not writing to database correctly


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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.