File Upload Script Problem

Discussion in 'PHP' started by Guernica, Mar 13, 2008.

  1. #1
    Here is my entire upload script code:

    		if($_GET['do'] == 'upload') {
    		
    		// check errors
    		
    			if(!isset($_FILES['uploadfile']['name'])) {
    				$error = "You must select a file to upload.";
    				}
    				else if(!isset($_POST['tos'])) {
    				$error = "You must agree to our Terms of Service.";
    				}
    				
    			if($error) {
    				echo "<font color='#f05b5b'><b>{$error}</b></font><br/>";
    			}
    		
    		if(!isset($error)) {
    		// no errors, proceed
    		
    		$filename = $_FILES['uploadfile']['name'];
    		$dir = "./files/";
    		$dir = $dir . basename($_FILES['uploadfile']['name']) ;
    		$ext = substr($filename, strrpos($filename, '.'));
    		$validtypes = array('.rar','.zip','.gzip','.jar');
    		$ok=1;
    		
    		$dbhost = 'localhost';
    		$dbuser = 'XXXXX';
    		$dbpass = 'XXXXX';
    
    		$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
    
    		$dbname = 'XXXXX';
    		mysql_select_db($dbname);
    		
    		if($_FILES['uploadfile']['size'] > "157286400") {
    			echo "<font color='#f05b5b'><b>This file is over the MB limit.</b></font><br/>";
    			$ok=0;
    		}
    		
    		else if(!in_array($ext,$validtypes)) {
    			echo "<font color='#f05b5b'><b>This is not a valid filetype.</b></font><br/>";
    			$ok=0;
    		}
    		else if (file_exists("files/" . $_FILES["uploadfile"]["name"])) {
    			echo "That filename already exists. Please rename and try again.";
    			$ok=0;
    		}
    				
    		if($ok == "1") {
    		
    			if(move_uploaded_file($_FILES['uploadfile']['tmp_name'], $dir)) {
    				echo "<font color='#68f08f'><b>The file ".  basename( $_FILES['uploadfile']['name']). 
        " has been uploaded successfully.</b></font><br/>";
    				
    				// QUERY
    				$filename = $_FILES['uploadfile']['name'];
    				$filesize = $_FILES['uploadfile']['size'] / 1024;
    				$filetype = $_FILES['uploadfile']['type'];
    				$date = date("Y-m-d");
    				$ip = $_SERVER['REMOTE_ADDR'];
    				$fid = $_FILES['uploadfile']['name'] . rand(100, 100000);
    				$url = "http://uber-warez.com/filehost/download.php?f=$fid";
    				
    				mysql_query("INSERT INTO files (fid, filename, size, type, date, ip) VALUES ('$fid', '$filename', '$filesize', '$filetype', '$date', '$ip')");
    				
    				
    				echo "<br/><b>Download Link:</b><br/><input type='text' name='url' size='60' value='{$url}' class='button' />";
    			} else {
    				echo "There was a problem uploading your file.";
    				print($_FILES["uploadfile"]["error"]);
    				}
    		}
    		}
    		
    	
    		}
    PHP:
    The problem: It only uploads files up to 1 mb, or so it seems. I have tried things over 1 mb and they don't work, under -- works. Gives the file is over the MB limit error.

    Obviously, "157286400" bytes is over 1mb, it is 150mb.

    Please help!
     
    Guernica, Mar 13, 2008 IP
  2. 00johnny

    00johnny Peon

    Messages:
    149
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    there are a few settings in you php.ini file you need to increase, first try:
    upload_max_filesize = 2M

    if that doesn't work try all of these, i remember doing this before and don't remember what the key variable was
    post_max_size = 8M
    max_execution_time = 30 ; Maximum execution time of each script, in seconds
    max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
    memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)
     
    00johnny, Mar 13, 2008 IP
  3. Guernica

    Guernica Peon

    Messages:
    268
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am not sure if I have access to that file but under what directory would it be? I might have to ask the host provider.

    Are you also saying that the problem doesn't lie in my script? Wanna make sure of that. :) Thank you!!
     
    Guernica, Mar 13, 2008 IP
  4. invmatt

    invmatt Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you're using a shared hosting provider I doubt you'll have access to the php.ini file, and in most cases they won't change the max file upload setting.
     
    invmatt, Mar 13, 2008 IP