Jump to content

Detect uploaded file


3raser

Recommended Posts

Why does the following code not detect the following file? After I select a file and I click upload, it goes back to the upload form.

 

<?php
include_once("includes/config.php");

//grab their type
if(!$_COOKIE['user'])
{	
//they are a guest
$info = "Guest";
}
else
{	
//they are a user
$info = $_COOKIE['user'];
}


if(!$_FILE['file'])
{
$content = '<form action="submit.php" method="post" enctype="multipart/form-data">
<label for="file">SELECT SKIN:</label>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>';
}
else
{
if($_FILES['file']['error'] > 0)
{
	$content = "There was an error trying to upload the skin ".$_FILES['file']['name'].".".$_FILES['file']['error'];
}

}

?>
<html>
<head>
<title><?php $title; ?></title>
<link rel="stylesheet" type="text/css" href="theme/style.css" />
</head>
<body>
<div id="header">
MCSkins
</div>

<?php echo "Submitting as: ".$info."<br/><br/>".$content; ?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/231885-detect-uploaded-file/
Share on other sites

Updated code:

 

<?php
include_once("includes/config.php");

//grab their type
if(!$_COOKIE['user'])
{	
//they are a guest
$user = "Guest";
}
else
{	
//they are a user
$user = $_COOKIE['user'];
}


if(!$_FILE['file'])
{
$content = '<form action="submit.php" method="post" enctype="multipart/form-data">
<label for="file">SELECT SKIN:</label>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>';
}
else
{
if($_FILES['file']['error'] > 0)
{
	$content = "There was an error trying to upload the skin ".$_FILES['file']['name'].".".$_FILES['file']['error'];
}
elseif($_FILES['file']['type'] == "image/png" || $_FILES['file']['type'] == "image/jpeg" || $_FILES['file']['type'] == "image/pjpeg")
{
	mysql_query("INSERT INTO skins VALUES (null, '$info', '". $_FILES['file']['name'] ."', '". date("M-d-Y") ."', '". $_SERVER['REMOTE_ADDR'] ."', 0, 0)");

	$_FILES['file']['name'] = mysql_insert_id();

	 move_uploaded_file($_FILES["file"]["tmp_name"],
	"skins/" . $_FILES["file"]["name"]);
}
else
{
	$content = "You have uploaded an invalid file format. Please only use a .jpeg or .png file format.";
}

}

?>
<html>
<head>
<title><?php $title; ?></title>
<link rel="stylesheet" type="text/css" href="theme/style.css" />
</head>
<body>
<div id="header">
MCSkins
</div>

<?php echo "Submitting as: ".$user."<br/><br/>".$content; ?>
</body>
</html>

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.