/    Sign up×
Community /Pin to ProfileBookmark

Upload Zip Files

Hi,

I have the following code

$max_file_size = ‘500000’;
$valid_file_type = “application/zip”;
$this_file_size = $_FILES[‘userfile’][‘size’];
$this_file_type = $_
FILES[‘userfile’][‘type’];

if ($max_file_size >= $this_file_size && $valid_file_type == $this_file_type)

etc..

However, when i upload a zip file about 150kb which should be accepted, i’m given the error message that the file is not in zip format.

Anything wrong with the above?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 19.2006 — From http://www.php.net/manual/en/features.file-upload.php#features.file-upload.post-method :
$_FILES['userfile']['type']

The mime type of the file, [color=red]if the browser provided this information[/color]. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore [color=red]don't take its value for granted[/color].[/quote]
You might have to explode the file name on "." and see if the last part is "zip".
Copy linkTweet thisAlerts:
@kevinmcqueenauthorJan 19.2006 — Any clues?

Never used explode before...

I've tried editing the following line

$this_file_type = $_FILES['userfile']['type'];

to

$this_file_type = explode(",",$_FILES['userfile'] ['name']);
Copy linkTweet thisAlerts:
@NogDogJan 19.2006 — Something like:
[code=php]
function get_suffix($filename)
{
$suffix = ""; // initialize to no suffix
$parts = explode(".", $filename);
if(count($parts) > 0) // there is a suffix
{
$suffix = strtolower(array_pop($parts)); // last array element in lower-case
}
return($suffix)
}
// USAGE
$type = get_suffix($_FILES['userfile']['name']);
if($type == "zip")
{
// it's a zip file
}
[/code]
Copy linkTweet thisAlerts:
@kevinmcqueenauthorJan 20.2006 — Thanks.

Much appreciated.

Kevin
Copy linkTweet thisAlerts:
@sungalyFeb 18.2006 — Hi,

I have the following code

$max_file_size = '500000';

$valid_file_type = "application/zip";

$this_file_size = $_FILES['userfile']['size'];

$this_file_type = $_
FILES['userfile']['type'];

if ($max_file_size >= $this_file_size && $valid_file_type == $this_file_type)

etc..

However, when i upload a zip file about 150kb which should be accepted, i'm given the error message that the file is not in zip format.

Anything wrong with the above?[/QUOTE]

I`ve the problem as like you..How will Videos upload and displaying in player when clicks
×

Success!

Help @kevinmcqueen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...