$_FILES[][] is empty

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
chopficaro
Forum Commoner
Posts: 68
Joined: Fri Jan 01, 2010 12:56 am

$_FILES[][] is empty

Post by chopficaro »

srry for repost
why is $_FILES[][] is empty?
form:

Code: Select all

<form enctype=\"multipart/form-data\" action=\"post.php\" method=\"post\">
  <label for=\"title\">Title</label>
  <input type=\"text\" name=\"title\" />
  <br />
  <label for=\"text\">Description</label>
  <input type=\"text\" name=\"text\" id=\"text\" />
  <br />
  <label for=\"price\">Price</label>
  <input type=\"text\" name=\"price\" id=\"price\" />
  <br />
  <label for=\"file\">Image</label>
  <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"200000000\" />
  <input type=\"file\" name=\"file\" id=\"file\" /> 
  <br />
  <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit\" />
</form>
post.php (file upload management starts line 65):

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Item Post</title>
<link rel="stylesheet" type="text/css" href="/css/mw3dailymedia.css?a=<%=now%>" />
</head>
<body>




<div id="content">
<div id="admin">
<table id="table">
 <?php
  
	// redifine variables for different server
	require_once "mysqlconfig.php";  
	require_once "textprep.php";  
	require_once "pagevars.php";
	$mysqlTableName=MYSQLTABLENAME;
	
	// connect to database
	$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); 
	if (!$connection)
	{
		die("Database connection failed: " . mysql_error());
	}
 
	// select database
	$db_select = mysql_select_db(DB_NAME,$connection);
	if (!$db_select)
	{
		die("Database selection failed: " . mysql_error());
	}
 	
	//get top rank
	$result = mysql_query("SELECT * FROM ".$mysqlTableName."", $connection);
	if (!$result) 
	{
		die("Database query failed: " . mysql_error());
	}
	$topRank=0;
	while ($row = mysql_fetch_array($result))
	{
		if($row["rank"]>$topRank)
		{
			//debug echo "<p>top rank ".$topRank.", current rank ".$row["rank"]."</p>";
			$topRank=$row["rank"];
		}
	}
	$rank=$topRank+1;

	// move all other ranks up one so we can fit new vid at number 1
		for($i=($rank-1);$i>=1;$i--)
		{
			$query="UPDATE ".$mysqlTableName." SET rank='".($i+1)."' WHERE rank='".$i."'";
			$result = mysql_query($query, $connection);
			if (!$result) 
			{
				die("Database UPDATE failed: " . mysql_error());
			}
		}
	// store picture
	$allowedExts = array("jpg", "jpeg");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists($_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "/menu/" . $_POST["title".".jpg"]);
      echo "Stored in: " . $_POST["title".".jpg"];
      }
    }
  }
else
  {
  echo "Invalid file";
  echo
"\ntype ".$_FILES["file"]["type"].
"\nsize ".$_FILES["file"]["size"];
  }


	// put variables into table
	$result = mysql_query("INSERT INTO ".$mysqlTableName." (name,description,price,rank) VALUES ('".mysql_prep($_POST["title"])."','".mysql_prep($_POST["text"])."','".mysql_prep($_POST["price"])."','".(1)."')", $connection);
	if (!$result)
	{
		die("Database INSERT failed: " . mysql_error());
	}
 
	// confirm that variables are on our server
	$result = mysql_query("SELECT * FROM ".$mysqlTableName."", $connection);
	if (!$result)
	{
		die("Database query failed: " . mysql_error());
	}
	while ($row = mysql_fetch_array($result)) {
		echo "<tr><td>name: ".$row["name"]."</td></tr><tr><td>description: ".$row["description"]."</td></tr><tr><td>price: ".$row["price"]."</td></tr><tr><td>rank: ".$row["rank"]."</td></tr>";
	}
 
?>
</table>
</div>
</div>
</body>
</html>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $_FILES[][] is empty

Post by requinix »

Make sure your php.ini has

Code: Select all

error_reporting = -1
display_errors = on
then do a

Code: Select all

print_r($_FILES);
for us to prove that it really is empty.
chopficaro
Forum Commoner
Posts: 68
Joined: Fri Jan 01, 2010 12:56 am

Re: $_FILES[][] is empty

Post by chopficaro »

wtf its working now...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $_FILES[][] is empty

Post by requinix »

Oh yeah, I forgot to mention: I hacked into your machine shortly after I posted, found the bug, and fixed it. Don't remember exactly what it was though - a typo, I think somewhere around the middle of the file.
Post Reply