Jump to content

[SOLVED] Call to undefined function move_uploadfile()


peter_anderson

Recommended Posts

I'm trying to perform a file upload on my script, but I get the error:

Fatal error: Call to undefined function move_uploadfile() in /home/..../index.php on line 350

 

Here is my code that performs uploads:

	<?php
//snip
case "uploadProcess":
	//if the user no logged in, show error
	if (!isset($_SESSION['active'])) { 
		$content = '<h2>For security reasons, you must be logged in to upload a file.<br />
			<br />Go back and login before attempting to upload.</h2>';
		$content .= '<p style="text-align: center; ">Powered by <a href="http://www.scriptboxer.com/download-site-script.php">DownloadBoxer v1</a>.<br />
		© <a href="http://www.scriptboxer.com">ScriptBoxer</a> - <a href="http://www.scriptboxer.com">PHP Scripts</a></p>';
		$html = str_replace('{content}', $content, $html);
		$html = str_replace('{title}', 'Upload File :: Upload FAILED', $html);
		echo $html;
		exit();
	}
	//else, let's up-fucking-load baby!
	$target_path = $config['uploaddir'];
	$target_path1 = $target_path . basename( $_FILES['uploadedfile']['name']); 
	$filelocation = $_FILES['uploadedfile']['tmp_name'];
	$ipadd = $_POST['ipadd'];
	echo ''.$_FILES['uploadfile']['tmp_name'].', '.$target_path1.'';
	if(move_uploadfile($_FILES['uploadfile']['tmp_name'], $target_path1)) {
		$fid = rand(1690, 16901690);
		$username = $_SESSION['username'];
		$query = "INSERT INTO files(owner, filelocation, ipadd, fid)
		 VALUES('$username', '$filelocation', '$ipadd', '$fid')";
		$content = '<h1>The file has been uploaded!</h1>
			<h2>You may download it <a href="?downloadFile&file='.$fid.'" target="_blank">here.</a></h2>
			<p>Thank you for uploading the file to our file sharing service.</p>
			<p>It has now been uploaded and is ready for downloads.</p>
			<p>Copy and paste this link for distributing the file.</p>
			<p>'.$_SERVER['SERVER_NAME'].'/?downloadFile&file='.$fid.'</p>';
		echo "The file ".  basename( $_FILES['uploadfile']['name'])." has been uploaded";
	} else{
		$content = '<h1>File Upload Error</h1>
			<h2>Oops, the file couldn&#39;t be uploaded!</h2>
			<p>The file you tried to upload has NOT been uploaded.</p>
			<p>This could be because:<br />
			- the file is already on the server<br />
			- the server is full<br />
			- the file was named the same as an already existing file<br />
			- the server is not accepting new uploads.</p>
			<p>Please contact our support team or the webmaster.</p>';
	}
	$content .= '<p style="text-align: center; ">Powered by <a href="http://www.scriptboxer.com/download-site-script.php">DownloadBoxer v1</a>.<br />
	© <a href="http://www.scriptboxer.com">ScriptBoxer</a> - <a href="http://www.scriptboxer.com">PHP Scripts</a></p>';
	$html = str_replace('{content}', $content, $html);
	$html = str_replace('{title}', 'Upload File :: Upload Results', $html);
	echo $html;
break;
default:
	$content = '<h1>Welcome!</h1>
		'.$config['welcomemsg'].'
		<h2>Upload your file</h2>';
	if (isset($_SESSION['active'])) { 
		$content .= '<form action="?action=uploadProcess" enctype="multipart/form-data" method="post" name="uploadForm">
			<p><input id="upload" style="width:80%;" name="uploadfile" type="file" />
			<input type="hidden" name="username" value="'.$_SESSION['username'].'" />
			<input type="hidden" name="ipadd" value="'.$_SERVER["REMOTE_ADDR"].'" />
			<input id="upload" name="upload" type="submit" value="Upload Now!" /></p>
			</form>';
	}else{
		$content .= '<h2>You must be logged in to upload!<br />
			<a href="?action=Members">Click here to login</a>.</h2>';
	}
	$content .= '<p style="text-align: center; ">Powered by <a href="http://www.scriptboxer.com/download-site-script.php">DownloadBoxer v1</a>.<br />
	© <a href="http://www.scriptboxer.com">ScriptBoxer</a> - <a href="http://www.scriptboxer.com">PHP Scripts</a></p>';
	$html = str_replace('{content}', $content, $html);
	$html = str_replace('{title}', 'Home :: Upload Now!', $html);
	echo $html;
break;

?>

 

Can anyone see what is wrong?

 

I've tried setting the upload directory to the full path, and just uploads/. The directory is 777 permissions.

 

Can anyone help? I suck at doing uploads :(

 

And if you see any potential security problems, please let me know.

To my knowledge (and according to your PHP) there is no such function as move_uploadfile(), I think you probably want move_uploaded_file().

 

Thanks :)

 

That fixed it, but it throws up my error for not uploading it.

 

Any ideas?

What error?

 

File Upload Error

 

Oops, the file couldn't be uploaded!

 

The file you tried to upload has NOT been uploaded.

 

This could be because:

- the file is already on the server

- the server is full

- the file was named the same as an already existing file

- the server is not accepting new uploads.

 

Please contact our support team or the webmaster.

 

(generated by:

<?php

//snip
} else{
		$content = '<h1>File Upload Error</h1>
			<h2>Oops, the file couldn&#39;t be uploaded!</h2>
			<p>The file you tried to upload has NOT been uploaded.</p>
			<p>This could be because:<br />
			- the file is already on the server<br />
			- the server is full<br />
			- the file was named the same as an already existing file<br />
			- the server is not accepting new uploads.</p>
			<p>Please contact our support team or the webmaster.</p>';
	}
//snip
?>

)

What error_reporting do you have turned on?

 

If filename  is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

 

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

What error_reporting do you have turned on?

 

If filename  is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

 

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

 

I've turned it all on (I think)

 

ini_set('display_errors','1');

ini_set('display_startup_errors','1');

error_reporting (E_ERROR);

I believe E_ERROR will only report fatal errors not warnings, if you change it to error_reporting (E_ALL), you should see the warning (assuming your getting one, which seems likely).

 

Thanks :)

 

It's now fixed.

 

Here's what was wrong:

- path missing trailing slash

- full path required

- variable spelling mistake

 

Thanks again

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.