3raser Posted March 27, 2011 Share Posted March 27, 2011 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> Quote Link to comment Share on other sites More sharing options...
3raser Posted March 27, 2011 Author Share Posted March 27, 2011 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> Quote Link to comment Share on other sites More sharing options...
3raser Posted March 27, 2011 Author Share Posted March 27, 2011 Bump! :-\ Quote Link to comment Share on other sites More sharing options...
3raser Posted March 27, 2011 Author Share Posted March 27, 2011 Bump once more... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.