Uploading Files Issue

Hi,

I have a form that allows user to upload files. However, the file does not appear on the site and the code returns no errors.

What issues could have occurred? The code worked previously and has not been changed.

Thanks.


<?php
session_start();
/***********************
 declare variables
***********************/
$group1 = $_POST['group1'];
$filename = $_FILES['userfile']['tmp_name'];
$submitfile = $_POST['submitfile'];

// declare an empty error array
$error_message = array();
$fileupload_message = array();

//ECHO '<p>Filepath:'.$filename.'</p>';

// if form submitted
if(isset($submitfile))
{
 		 /*************************
		  Form Error Checking
		 *************************/
     if(!$filename || $filename == "")
     {
		 //ECHO '<p>File not entered</p>';
        $error_message['username'] = 'Please Enter Filename';
     }
		 if(!$group1 || $group1 == "")
		 {
		 		 //echo '<p>Radio Button not selected</p>';
         $error_message['group1'] = 'Please Select Where to Publish to.';
		 }
		 
		 /*************************
		  End Form Checking
		 *************************/

    /*********************************
     If No Form Errors
    *********************************/
    if(count($error_message) == 0)
    {  
				// set path to upload doc
				if($_POST['group1'] == "policy_business")
				{
				 				$uploaddir = 'documents/policy/';
				}
				else if($_POST['group1'] == "policy_service")
				{
								$uploaddir = 'documents/policy/service/';
				}			
				

        $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
        if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
            //echo "File is valid, and was successfully uploaded.\
";
        		$fileupload_message['fileUploaded'] = 'File is valid, and was successfully uploaded.';						
        } else {
            //echo "Possible file upload attack!\
";
        		$fileupload_message['fileUploaded'] = 'File Upload Failed.';						
        }
        
								 										 
     }// end if

}// end isset $submit
?>

Probably a file path issue with move_uploaded_file().

I’ve had this many times. It can be very frustrating to get working too.

Any suggestions? What kind of issue? Thanks.

Well it either doesn’t like one of the paths or you have a permission issue. Without debugging your code there is not much more i can say.