473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

file/directory format/size help

Hi

I am writing a script to upload images. How do I check the format of
the file? How can I tell if the file is an image, movie, or text file?
I would also like to put a limit on how much a user can upload. So how
can I check how many bits, bytes, mb, gb are in a folder.

So that sums up to

#1 What type of file is the file? Is it a movie, image, or text
document?
#2 What particular form is the file jpeg, bmp, gif etc.?
#3 The size of a directory?

Thanks

Dec 24 '06 #1
2 1429
On Sun, 24 Dec 2006 07:45:32 -0800, moishyyehuda wrote:
Hi

I am writing a script to upload images. How do I check the format of
the file? How can I tell if the file is an image, movie, or text file?
I would also like to put a limit on how much a user can upload. So how
can I check how many bits, bytes, mb, gb are in a folder.

So that sums up to

#1 What type of file is the file? Is it a movie, image, or text
document?
In the Windows world, one simply looks at the file extension (e.g. .gif,
..avi, .txt, etc.) and hopes that it is correct.

In the Linux world, there is a command "file" that tries to guess the file
type, by looking at some combination of extension and/or signature bytes
inside the file.

Classic Macintosh OS kept file-type metadata as part of the file system; I
don't know what OS X based Macintoshes do.

Why do you care what the format of the file is? Can't you let the user
upload whatever file they like?

#2 What particular form is the file jpeg, bmp, gif etc.?
I don't understand the question. What do you mean "form"?

#3 The size of a directory?
Directories themselves generally are a fixed size, e.g. on my ext3 file
system my directories are typically 4K in size. But that's probably not
what you mean :-)

I assume you mean the size of all the files in a directory combined. You
have to get the size of each file, and add them all together. If you use
Google, you will find Python code to do that. Try looking on the
ActiveState Python Cookbook:

http://aspn.activestate.com/ASPN/Python/Cookbook/

--
Steven.

Dec 24 '06 #2
>#1 What type of file is the file? Is it a movie, image, or text
document?

In the Windows world, one simply looks at the file extension (e.g. .gif,
.avi, .txt, etc.) and hopes that it is correct.
or simply use TRID:
http://mark0.net/soft-trid-e.html

Stef Mientki
Dec 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
10
by: John Ratliff | last post by:
What is the best way to determine a file's size? Should I use stat? Is this a better way? std::fstream file("myfile", std::ios_base::in | std::ios_base::binary); file.seekg(0,...
2
by: Phil Galey | last post by:
Using the following, you can determine the size of a file: Dim fi As New IO.FileInfo(<Path to file>) MsgBox(fi.Length) .... but what about the size of a directory? The IO.DirectoryInfo object...
1
by: lactaseman | last post by:
While I know this is not the correct venue... I realize this is of little to no importance to most out there... however, if I had found this in my initial searches, I would have used this. So, as...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: levimc | last post by:
I know that that topic may be old to you but I looked at other more- than-two-year-old topics related to mine. However, I didn't find them working for my project at all because its errors return...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.