Help in File Uploads.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oneplusdave
Forum Newbie
Posts: 5
Joined: Thu Jul 29, 2010 12:31 am

Help in File Uploads.

Post by oneplusdave »

I am relatively new to PHP, so I need help why this script is not functioning


Code: Select all

if ($actionis=='Add Resource'){

//declaration of directory where files are saved


if(isset($_POST['file']))
{
//setting of variables

$uploaddir = "resources/";

$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileErr = $_FILES['userfile']['error'];

$filePath= $uploaddir . basename($_FILES['userfile']['name']);


global $filePath;

//filters extension filename
$fileX = strrchr($fileName,".");

/*
* UPLOAD FILTERING OPTIONS
*/

if ($fileSize>1000000){
die ("File too large! Must be below 1Mb.");
}
else{
if (($fileX==".txt")||($fileX==".doc")||($fileX==".docx")||($fileX==".pdf")||($fileX==".ppt")||($fileX==".pptx")){

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filePath)){
echo "<code>SUCCESS! File Uploaded.</code>&nbsp;&nbsp;".$fileErr;
}
else{
echo "<code class='red'>Upload Failed.</code>";
}

 }
else{
die ("Wrong file format!");
	}
		}
}


The above script does not generate an error. But my problem is that I cannot save the uploaded file into my selected directory.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Help in File Uploads.

Post by superdezign »

Are you getting any output at all? It's possible that you have error_reporting turned off. It is especially important to have this turned on during the development process. Use the error_reporting() function to turn it on.
Post Reply