3raser Posted January 8, 2011 Share Posted January 8, 2011 This is my first time ever working with this type of stuff with PHP. So, I basically got this code from a tutorial at Tizag on how to upload files to your webiste. But everytime I do, I get an error message. I don't get a PHP error, I just get it from the code. "There was an error uploading the file, please try again!" <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; echo $output; $_FILES['uploadedfile']['name'] = $output; echo $_FILES['uploadfile']['name']; $target_path = "mods/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The mod ". basename( $_FILES['uploadedfile']['name']). " has been uploaded. Check it out HERE."; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } include("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/ Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Post the form also, plz. Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1156763 Share on other sites More sharing options...
3raser Posted January 8, 2011 Author Share Posted January 8, 2011 Post the form also, please. Sure thing. <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } elsea { echo '<form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000000 byte" /> Choose a Plugin to Upload: <input name="file" type="file" /><br /> <b>Title:</b> <input type="text" name="title"><br/> <b>Description</b><br/><textarea name="description" cols="45" rows="25"></textarea> <br/> <input type="submit" value="Upload Plugin" /> </form>'; echo "<br/><br/>"; echo "NOTE: Uploading any harmful programs and/or files that can invade another users privacy, harm their computer, or uploading any files like malware, viruses, or trojans will result in an INSTANT, PERMANENT, IP Ban."; } ?> <? include("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1156775 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Where ever you're currently referencing the file that was uploaded, you need to use $_FILES['file']['{whatever}'], instead of $_FILES['uploadedfile'][' . . . since file is the name of the field in the form. Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1156783 Share on other sites More sharing options...
3raser Posted January 8, 2011 Author Share Posted January 8, 2011 Where ever you're currently referencing the file that was uploaded, you need to use $_FILES['file']['{whatever}'], instead of $_FILES['uploadedfile'][' . . . since file is the name of the field in the form. So what goes in {whatever}? Sorry. :/ Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1156803 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Sorry, whatever is already there would just stay there . . . The value in the second set of [brackets] would remain unchanged. Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1156806 Share on other sites More sharing options...
3raser Posted January 11, 2011 Author Share Posted January 11, 2011 Sorry, whatever is already there would just stay there . . . The value in the second set of [brackets] would remain unchanged. How do I get it so it will check what extension it has? Like if it's .txt, or .zip Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1157675 Share on other sites More sharing options...
Pikachu2000 Posted January 11, 2011 Share Posted January 11, 2011 You can use pathinfo, with PATHINFO_EXTENSION for that. Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1157688 Share on other sites More sharing options...
3raser Posted January 12, 2011 Author Share Posted January 12, 2011 You can use pathinfo, with PATHINFO_EXTENSION for that. Thank you! :0 Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1158583 Share on other sites More sharing options...
3raser Posted January 12, 2011 Author Share Posted January 12, 2011 After further research, I learned a bit more. But where do I put the ['extension'] part? echo "You cannot use a ". PATHINFO(basename($_FILES['file']['name']['extension'])) ." extension!"; Quote Link to comment https://forums.phpfreaks.com/topic/223802-upload-error/#findComment-1158593 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.