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
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>

Link to comment
Share on other sites

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.