Jump to content

File upload using PHP


sudeepr71

Recommended Posts

Hi,

 

I'm trying to create a website that will allow users to upload video files that are less than 100mb. Right now, I can only get a video file that is less than 8mb to upload. I've got it hosted on GoDaddy. They told me to change the php.ini file to:

 

memory_limit = 1000M
post_max_size = 100M
file_uploads = On
upload_max_filesize = 100M

 

Here is the entire php.ini file:

 

register_globals = off
allow_url_fopen = off

expose_php = Off
variables_order = "EGPCS"
extension_dir = ./
upload_tmp_dir = /tmp
precision = 12
memory_limit = 1000M
post_max_size = 100M
file_uploads = On
upload_max_filesize = 100M
SMTP = relay-hosting.secureserver.net
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="

[Zend]
zend_extension=/usr/local/zo/ZendExtensionManager.so
zend_extension=/usr/local/zo/4_3/ZendOptimizer.so

 

I've tried everything and need a lot of help! Below is my code for uploading. It first removes the extension from the file. Then renames it with a randomly generated number. Next, it a "." and then finally the extension. Lastly, it moves the file from the temp to the "uploads" folder.

 

<?php 

//path where we want to upload the files to on the server
$target_path = "uploads/";

// random number generator
function createRandomPassword() 
{
$chars = "023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 6) 
{
	$num = rand() % 15;
	$tmp = substr($chars, $num, 1);
	$pass = $pass . $tmp;
	$i++;
}
return $pass;
}


$autopw = createRandomPassword();

//Separates the extension from the rest of the file name and returns it
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}

//This applies the function to our file
$ext = findexts ($_FILES['uploadedfile']['name']) ; 


//This adds a . to the end of our random number
$key = $autopw.".";
//This adds the extension to the end
$target_path = $target_path . $key.$ext;



//This moves the file from temp to our uploads directory and then confirms it
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 

   {	
       echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded as ". $key.$ext; 
  } 
   
  else{
    echo "There was an error uploading the file, please try again!";
}

?> 

 

Like I said before, I can upload a file that is less than 8mb. Anything bigger, I get the error message. Please help me, I need to figure this out asap!

 

Link to comment
Share on other sites

THis might help ..

 

The apache webserver has a LimitRequestBody configuration directive that restricts the size of all

POST data regardless of the web scripting language in use. Some RPM installations sets limit request

body to 512Kb. May need to change this to a larger value or remove the entry altogether.

 

Steven M

Link to comment
Share on other sites

Your code has no error checking for upload errors, so you don't really know why it is failing for larger files. You should be checking the ['error'] element of the uploaded file information. As a minimum, just for debugging, add the following -

 

echo "<pre>";
echo "FILES:";
print_r($_FILES);
echo "</pre>";

Link to comment
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.