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> Link to comment https://forums.phpfreaks.com/topic/231885-detect-uploaded-file/ 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> Link to comment https://forums.phpfreaks.com/topic/231885-detect-uploaded-file/#findComment-1192998 Share on other sites More sharing options...
3raser Posted March 27, 2011 Author Share Posted March 27, 2011 Bump! :-\ Link to comment https://forums.phpfreaks.com/topic/231885-detect-uploaded-file/#findComment-1193008 Share on other sites More sharing options...
3raser Posted March 27, 2011 Author Share Posted March 27, 2011 Bump once more... Link to comment https://forums.phpfreaks.com/topic/231885-detect-uploaded-file/#findComment-1193020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.