Jump to content

Upload Error


3raser

Recommended Posts

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");
?>

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

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. :/

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.