Jump to content

Recommended Posts

Hi Gurus,

 

I am using php to upload files from a web browser to a linux server. Small files less than about 1Mb are no problem but larger ones cannot get uploaded. In fact 20Mb files will cause the web browser to hang.

 

I have set the php.ini file as follows ...

 

upload_max_filesize 100M 100M

 

This makes no difference !! Has anyone got any ideas ??

 

Here is the function that I am using ....

<?php
function uploadfile($message, $path, $file_type, $file_size, $file_content)
{
 // set error flag
 $file_flag = false;

 // check for spaces in filename
 if(strpos($_FILES["moh_file"]["name"], ' ') == true)
    {
	  $message = 'Error: file name should not contain spaces';
	  return $file_flag;
	} 

 // echo $path; die();

 // set passed variables
 $file_type = $_FILES["moh_file"]["type"];
 $file_size = $_FILES["moh_file"]["size"];

 // check for content
 if($_FILES['moh_file']['size'] == 0)
   {
	$message = 'Error: file has no content (no upload)';
	return $file_flag;
   }

 // check for size
 if($_FILES["moh_file"]["size"] > $_POST['MAX_FILE_SIZE'])
   {
	$message = 'Error: file is too large (no upload)';
	return $file_flag;
   }

 // check audio file type                 
 if ($_FILES["moh_file"]["type"] == "audio/wav" || 
	 $_FILES["moh_file"]["type"] == "audio/wave" || 
	 $_FILES["moh_file"]["type"] == "audio/x-wav" ||
	 $_FILES["moh_file"]["type"] == "audio/mpeg" ||
	 $_FILES["moh_file"]["type"] == "audio/mp3" ||    
	 $_FILES["moh_file"]["type"] == "audio/x-mpeg" ||
	 $_FILES["moh_file"]["type"] == "audio/gsm" ||  
	 $_FILES["moh_file"]["type"] == "audio/x-gsm" || 
	 $_FILES["moh_file"]["type"] == "application/ogg")   
  {
   if ($_FILES["moh_file"]["error"] > 0)
	{
	 $message = 'Error: invalid upload (error code: ' . $_FILES["moh_file"]["error"] . ')';
	 return $file_flag;
	}
   else
	{   
	 if (file_exists($path . $_FILES["moh_file"]["name"]))
	   {
		$message = 'Error: file ' . $_FILES["moh_file"]["name"] . ' already exists.' ;
		return $file_flag;
	   }
	 else
	   {
		if(move_uploaded_file($_FILES["moh_file"]["tmp_name"], $path . $_FILES["moh_file"]["name"]) == false)
		  {
		   $message = "Error: file not uploaded to : " . $path . $_FILES["moh_file"]["name"];
		   return $file_flag;
		  }
		else
		  {   
		   $message = "File uploaded to : " . $path . $_FILES["moh_file"]["name"];
		   $file_flag = true;
		  }
	   }
	} // end of first else

  }
 else
  {
	$message = "Error: invalid file format (no upload)";
	return $file_flag;
  }
  
 return $file_flag; 
}

 

regards,

 

Steven M

Link to comment
https://forums.phpfreaks.com/topic/99380-solved-uploading-large-files/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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