Jump to content

[SOLVED] passing $_FILES array into function


trekerboy

Recommended Posts

Hello,

 

I would like to create a function that uploads files and I am running into a roadblock using the superglobal $_FILES variable.

 

In my upload.php function I set $uploadfile = $_FILES['uploadfile']; then passing my uploadFile function $upload file. Where I run into problems is when I try to use the move_uploaded_file function and pass it $uploadfile['tmp_name']. I get a "failed to open stream: Is a directory..." error. Is $uploadfile['tmp_name'] equivalent to $_FILES['uploadfile']['tmp_name'] in this case or must I use $_FILES['uploadfile']['tmp_name'] everytime I must refer to the temp name of the uploaded file?

 

Thanks for any suggestions!

 

- Jason

 

Code in question:

 

in functions.php:

 

<?php
// Do uploads if there were no errors

		$uploaddir = 'phpupload/';
		$uploadfile = $uploaddir . basename($_FILES['uploadfile']['name']);

		if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploadfile)) 
		{
			echo "File is valid, and was successfully uploaded.\n";
		} 
		else 
		{
			echo "Possible file upload attack!\n";
		}

		echo 'Here is some more debugging info:';
		print_r($_FILES);
?>

 

upload.php:

 

<?php
require 'config.php';
require 'connectdb.php';
require 'functions.php';

$uploadfile = $_FILES['uploadfile'];
$uploaddir = $_POST['uploaddir']; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
$uploadfiledesc = $POST['uploadfiledesc'];
$uploadfilecategory = $POST['uploadfilecategory'];

$allowedext = array("jpg","jpeg","gif","png","pdf"); // These are the allowed extensions of the files that are uploaded
$maxsize = "2048000"; // Size in bytes
//	$maxheight = "100"; // This is in pixels - Leave this field empty if you don't want to upload images
//	$maxwidth = "100"; // This is in pixels - Leave this field empty if you don't want to upload images

if(uploadFile($uploadfile, $maxsize, $allowedext))
{
	echo "Got into uploadFile function loop. <br>";
}
else
{
	echo "uploadFile function returned false. <br>";
}
?>

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.