Jump to content

Upload Error


3raser

Recommended Posts

Why does it give me the "There was an error uploading the file, please try again!" error message?

 

I've checked through the code, and I've looked to see what is wrong. I'm thinking it MIGHT be because of:

 

		$target_path = $target_path . $output; 

		if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip")
		{

		if(move_uploaded_file($output, $target_path)) {

 

But, heres the full code:

 

<?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
	{
	echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>";

	$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);
	$user = $_SESSION['SESSION'];

		$target_path = "mods/";


		$query = mysql_query("SELECT COUNT(id) FROM mods");
		$finish_query = mysql_fetch_assoc($query);
		$output = $finish_query['COUNT(id)'] + 1;

		$target_path = $target_path . $output; 

		if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip")
		{

		if(move_uploaded_file($output, $target_path)) {

		echo "The mod ". basename($_FILES['file']['name']) . 
		" has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>";


		mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')");

		} else{
		echo "There was an error uploading the file, please try again!";
		}
		}
		else
		{
			echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only file extension allowed.";
		}
	}
include("includes/footer.php");
?>

Link to comment
Share on other sites

Newest code, still doesn't work:

 

<?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
	{
	echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>";

	$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);
	$user = $_SESSION['SESSION'];

		if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip")
		{

		$query = mysql_query("SELECT COUNT(id) FROM mods");
		$finish_query = mysql_fetch_assoc($query);
		$output = $finish_query['COUNT(id)'] + 1;

		$target_path = "mods/";
		$_FILES['file']['name'] = $output.".zip";
		$target_path = $target_path . basename($_FILES['file']['name']); 

		if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) {

		echo "The mod ". $title .
		" has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>";


		mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')");

		} else{
		echo "There was an error uploading ". $_FILES['file']['name'] ." the file, please try again!";
		}
		}
		else
		{
			echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only file extension allowed.";
		}
	}
include("includes/footer.php");
?>

Link to comment
Share on other sites

i don't see error_reporting turned on in your script. is it turned on in php.ini?

 

i don't see the code that would cause this output:

 

There was an error uploading the file, please try again!9 BREAK /mods/9.zip

 

} else{
		echo "There was an error uploading ". $_FILES['file']['name'] ." the file, please try again!";
		}

 

I get this with errorreporting(E_ALL);

 

Notice: Undefined index: SESSION in /home/a8079066/public_html/upload.php on line 26

 

As you see, no errors. (Just a small session one, which does no help)

Link to comment
Share on other sites

the undefined index notice tells you that $_SESSION['SESSION'] is undefined. $_SESSION['SESSION'] is not set. don't know if that is responsible for the other issue, but you shouldn't see any notices, errors or warnings if everything is okay.

 

Where is the 9 BREAK /mods/9.zip coming from in this line?

 

There was an error uploading the file, please try again!9 BREAK /mods/9.zip

Link to comment
Share on other sites

the undefined index notice tells you that $_SESSION['SESSION'] is undefined. $_SESSION['SESSION'] is not set. don't know if that is responsible for the other issue, but you shouldn't see any notices, errors or warnings if everything is okay.

 

Where is the 9 BREAK /mods/9.zip coming from in this line?

 

There was an error uploading the file, please try again!9 BREAK /mods/9.zip

 

$_FILES['file']['name'] = $output.".zip";
		$target_path = $target_path . basename($_FILES['file']['name']); 

 

and

 

echo "There was an error uploading ". $_FILES['file']['name'] ." the file, please try again!";

Link to comment
Share on other sites

This:

	if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) 

is not correct. You should be moving the temporary file (created by the upload process) to your desired destination.  The 'name' element of the FILES array, is the filename from the user's system - well, it was before you changed it a couple of lines above. The uploaded file, the one you need to move is in the 'tmp_name' element of the array -- and do NOT use the basename() function on it.

 

	if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) 

Link to comment
Share on other sites

This:

	if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) 

is not correct. You should be moving the temporary file (created by the upload process) to your desired destination.  The 'name' element of the FILES array, is the filename from the user's system - well, it was before you changed it a couple of lines above. The uploaded file, the one you need to move is in the 'tmp_name' element of the array -- and do NOT use the basename() function on it.

 

	if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) 

 

Wow....thank you.

 

And why not use basename?

Link to comment
Share on other sites

basename() strips off the path component, leaving only the filename and extension. I don't think the tmp_name will usually have a path component, so it shouldn't really matter - however, if PHP were to put a path component on the tmp_name, it would need to be there for move_uploaded_file() to work.

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.