Jump to content

[SOLVED] File upload question? . . or problem rather!


Solarpitch

Recommended Posts

Hey Guys,

 

Below is a snippet of my file upload script thats causing a problem. Everytime I try to upload a file it seems to fail and output the defined error of "The submitted file was invalid."

 

The file I am submitting is a jpg, 760kb. The file name is "pict0001.jpg". The script seems to work fine for smaller files but anything past 500kb or so just seems to fail. Anyone any ideas why . . . cause I am stumpted!

 

function generate_rand($l){
$c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$l; $i++)
{
$rand.= $c[rand()%strlen($c)];
}
return $rand;
}

$uploaddir = "user_images/";
$maxfilesize = 1048576; //1 megabyte
$filename = $_FILES['userfile']['name'];
$filesize = $_FILES['userfile']['size'];
$filetmpname = $_FILES['userfile']['tmp_name'];
$valid = array (".jpg",".gif",".png");
if ($filename) {
$error = "";
if ($filesize == 0) {
$error_file .= "The submitted file was invalid.<br />";

$execute = "no";
}
$type = strtolower(strstr($filename, '.'));
if (!in_array($type, $valid)) {
$error_file .= "The submitted file was of invalid type.<br />";

$execute = "no";
}
if ($filesize>$maxfilesize) {
$error_file .= "The submitted file was larger than a Megabyte.<br />";

$execute = "no";
}

Link to comment
Share on other sites

Wow 5000 bytes? ;)

 

Than I can no longer help you anymore. I'm only able to solve problems that I have experienced myself (I'm not an expert). Well just wait a little, there are so many people here on this forum that know so much more than me that I'm pretty sure you will get it to work!

 

Kind regards,

Sebas.

Link to comment
Share on other sites

Thanks . .just as you posted that I figured it out.

 

The problem was with the HTML

 

<input  type="hidden" name="MAX_FILE_SIZE" value="20000)">

 

should of been...

 

<input  type="hidden" name="MAX_FILE_SIZE" value="1048576)">

 

It was causing a conflict! Thanks anyway!

 

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.