trekerboy Posted August 19, 2007 Share Posted August 19, 2007 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/65729-solved-passing-_files-array-into-function/ Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 with this funtion uploadFile($uploadfile, $maxsize, $allowedext) you should use move_uploaded_file($uploadfile['tmp_name'], $uploadfile['name']) i think thats what you asked! Link to comment https://forums.phpfreaks.com/topic/65729-solved-passing-_files-array-into-function/#findComment-328334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.