473,657 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Upload

Hello,

I want to upload files via an HTML form and store them somewhere on my
webspace. So far so good. I am just a bit concerned about security issues
and traffic. My provider has set a file size limit of 20MB in php.ini. My
questions are:

1) If some evil web terrorist tries to upload a file which is larger than
the maximum allowed by the setting in php.ini - will the transfer be
cancelled by the server when the limit is reached so that there will not be
unnecessary traffic or will the whole file still be transmitted to the
server?
2) If the transfer is cancelled, is there a way for me to limit the maximum
upload file size to *less* than what my provider specifies - serverside?
3) How can I prevent evil people from uploading file after file (using some
automated process) and thus filling up my webspace and using up my monthly
traffic volume?

Thanks and greetings,
Thomas

P.S.: Does this NG have a FAQ?

--

Jul 16 '05 #1
11 6426
> I want to upload files via an HTML form and store them somewhere on my
webspace. So far so good. I am just a bit concerned about security issues
and traffic. My provider has set a file size limit of 20MB in php.ini. My
questions are:
Is this going to be for the public to upload, or just you? If its just you
you can have some sort of authentication on the page before they get the
upload form. If not you will be able to track the uploads if you have the
form on posting write their IP, and maybe some other details to a file.
Then on uploads check that file for the IP and dates / sizes, and if they're
uploading too much too quickly just don't allow the upload. The script to
do that would also check for old upload records and delete them from the log
file if necessary so it doesn't just keep growing.
1) If some evil web terrorist tries to upload a file which is larger than
I think 'evil web terrorists' have better things to do than fill up your
20MB!
2) If the transfer is cancelled, is there a way for me to limit the maximum upload file size to *less* than what my provider specifies - serverside?
Yeah - just on your processing of the upload examine the file size - if its
too big reject it. You have to write the code to move the file from the
temp dir to your own directory, so you can do whatever you like to the file.
3) How can I prevent evil people from uploading file after file (using some automated process) and thus filling up my webspace and using up my monthly
traffic volume?
See above - you can check anything you like, and a simple script and log
file would sort this out.
P.S.: Does this NG have a FAQ?


Not that I know of - but the PHP documentation is usually very good. The
web based version of the docs also have user comments on, a lot of which can
be helpful if you're stuck with something.

David
Jul 16 '05 #2
Also sprach David Walker:

[File Upload]
Is this going to be for the public to upload, or just you?
It's for the public.
If its
just you you can have some sort of authentication on the page before
they get the upload form. If not you will be able to track the
uploads if you have the form on posting write their IP, and maybe
some other details to a file. Then on uploads check that file for the
IP and dates / sizes, and if they're uploading too much too quickly
just don't allow the upload. The script to do that would also check
for old upload records and delete them from the log file if necessary
so it doesn't just keep growing.


Thanks for the suggestion. I will try something like that.
1) If some evil web terrorist tries to upload a file which is larger
than


I think 'evil web terrorists' have better things to do than fill up
your 20MB!


Still, if someone doesn't like me as much as (s)he should, they might try
bad jokes like this. Besides, the 20MB is the maximum file size for uploads,
not my total web space. Following your above suggestion, however, should
make any misuse much harder.
2) If the transfer is cancelled, is there a way for me to limit the
maximum upload file size to *less* than what my provider specifies -
serverside?


Yeah - just on your processing of the upload examine the file size -
if its too big reject it.


This, however, means that the whole file was already completely transmitted
to the server, and some of my free monthly transfer budget has been used up
in the process. I am looking for a solution which will prevent any data
transfer to the server exceeding a specified limit. There is MAX_FILE_SIZE
to specify a size limit client side, but as it's client side one cannot rely
on it, especially if someone tries to deliberately get around it.
P.S.: Does this NG have a FAQ?


Not that I know of - but the PHP documentation is usually very good.
The web based version of the docs also have user comments on, a lot
of which can be helpful if you're stuck with something.


Yes, that's true. Still, I'd like some more explanation on how "things are
handled" internally. For example, if setting a maximum size for upload files
in php.ini means that the server will somehow cancel the transmission
process when the limit is reached, and thus preventing traffic "over the
limit".

--

Jul 16 '05 #3
> This, however, means that the whole file was already completely
transmitted
to the server, and some of my free monthly transfer budget has been used up in the process. I am looking for a solution which will prevent any data
transfer to the server exceeding a specified limit. There is MAX_FILE_SIZE
to specify a size limit client side, but as it's client side one cannot rely on it, especially if someone tries to deliberately get around it.
Not really sure how it works unfortunately. I think it does probably stop
the uploads once its past the PHP file limit - as far as I remember it will
either just cut the file off at that point and save it as it is (incomplete)
or will just reject the transfer - this I think depends on the setting
somewhere when you're doing the upload handling in PHP.
Yes, that's true. Still, I'd like some more explanation on how "things are
handled" internally. For example, if setting a maximum size for upload files in php.ini means that the server will somehow cancel the transmission
process when the limit is reached, and thus preventing traffic "over the
limit".


Unfortunately as I just mentioned above I don't really know myself. I'm
pretty sure it would stop the upload if its a PHP size limit - I think PHP
is probably clever enough to know to do that.
Incidentally, I think you can change the PHP.ini settings dynamically for
individual pages - use ini_set - if you look in the PHP docs its all in
there how to do it so you could change the limit for individual pages, and
it'd be impossible for the client to get around it.

David
Jul 16 '05 #4
Also sprach David Walker:
Incidentally, I think you can change the PHP.ini settings dynamically
for individual pages - use ini_set - if you look in the PHP docs its
all in there how to do it so you could change the limit for
individual pages, and it'd be impossible for the client to get around
it.


I just had a look at the php manual - well, I *can* modify
"upload_max_fil esize" using ini_set(), but when my script processes this
command, the file will already have been uploaded, so my change will come
too late (a design bug)?

BTW, how does "post_max_s ize" influence "upload_max_fil esize"? I mean,
files are uploaded via "post", so what's the effective size limit if
post_max_size=8 M and upload_max_file size=20M, as it is the case with my
provider? He has PHP running as CGI, not as an Apache module - does this
make any difference?

--

Jul 16 '05 #5
> > Incidentally, I think you can change the PHP.ini settings dynamically
for individual pages - use ini_set - if you look in the PHP docs its
all in there how to do it so you could change the limit for
individual pages, and it'd be impossible for the client to get around
it.
I just had a look at the php manual - well, I *can* modify
"upload_max_fil esize" using ini_set(), but when my script processes this
command, the file will already have been uploaded, so my change will come
too late (a design bug)?


If you put that at the top of the page recieving the upload, then that page
should I think be read before the upload starts. If not, try putting it on
both the sending and recieving page, and then its bound to be there
somewhere.
BTW, how does "post_max_s ize" influence "upload_max_fil esize"? I mean,
files are uploaded via "post", so what's the effective size limit if
post_max_size=8 M and upload_max_file size=20M, as it is the case with my
provider? He has PHP running as CGI, not as an Apache module - does this
make any difference?


The best advice I can give here is to just try it. Play about with the
settings, try to upload different files, and see what it lets you do. Its
often easier than trying to predict behaviour not given in the manual - I do
a lot of my stuff just by testing simple scripts first, and once they work
transfer it to the proper page.
Otherwise someone else may be able to offer help - I haven't done enough
with uploads to really know, i've just allowed simple uploads to be done,
and move them - i don't have to worry about bandwidth or disk space, and the
page is protected so only a few people can access it anyway.
Good luck!

David
Jul 16 '05 #6
Also sprach David Walker:
I just had a look at the php manual - well, I *can* modify
"upload_max_fil esize" using ini_set(), but when my script processes
this command, the file will already have been uploaded, so my change
will come too late (a design bug)?
If you put that at the top of the page recieving the upload, then
that page should I think be read before the upload starts.


But the upload is part of the request for this page sent by the client. The
php script is called only after all of the client's request including post
data has been received - or am I wrong?
If not,
try putting it on both the sending and recieving page, and then its
bound to be there somewhere.


Even if I put it on the page that generates the upload form - as soon as
that page is sent out to the client the process is finished and the
ini_set() setting is lost. Or am I wrong again?

As for the precedence of different ini settings - I think you are right -
the best thing to do is try it out.

Thanks,
Thomas
Jul 16 '05 #7
> > If you put that at the top of the page recieving the upload, then
that page should I think be read before the upload starts.
But the upload is part of the request for this page sent by the client.

The php script is called only after all of the client's request including post
data has been received - or am I wrong?
Not really sure how it works to be honest. I was thinking that it should
just so that things like this would work... then again, if you do upload a
big file the page never goes until the upload is complete. So, maybe
putting it on the sending page, as I said below might be a better idea???
If not,
try putting it on both the sending and recieving page, and then its
bound to be there somewhere.


Even if I put it on the page that generates the upload form - as soon as
that page is sent out to the client the process is finished and the
ini_set() setting is lost. Or am I wrong again?


Well I was thinking it must get the setting from one page or the other
otherwise theres no point in having it. Since the browser stays on the
sending page until the upload is complete it looks like this is more likely
to work.
As for the precedence of different ini settings - I think you are right -
the best thing to do is try it out.


Yeah - just shove it on a little script, see what happens.

David
Jul 16 '05 #8
Also sprach David Walker:
Not really sure how it works to be honest. I was thinking that it
should just so that things like this would work... Well I was thinking it must get the setting from one page or the other
otherwise theres no point in having it.


Well, ini_set() is not just for setting this one option. It certainly works
fine with other things, only in this special case it is not very helpful.
But as PHP is running as a CGI with my provider, doesn't this mean I have my
very own "environmen t" all to myself, so theoretically I should be allowed
to modify "my" php.ini somehow? What actually is the difference between
those local and master values that phpinfo() reports?

Greetings, Thomas
Jul 16 '05 #9
> Well, ini_set() is not just for setting this one option. It certainly
works

It doens't have all the values there though, so if they allowed that value
to be changed then it must do something. I now think that it must take
affect on the calling page if anything.
fine with other things, only in this special case it is not very helpful.
But as PHP is running as a CGI with my provider, doesn't this mean I have my very own "environmen t" all to myself, so theoretically I should be allowed
to modify "my" php.ini somehow? What actually is the difference between
those local and master values that phpinfo() reports?


To be honest i've never seen a difference between the Local and Master
values on any server yet. I don't think its to do with CGI though - thats
just a different way to get PHP to work, but it is usually a master thing
for the whole server, not separate for individual folders or whatever.
Unless they've given you access via something other than FTP or web based
uploads though, theres no way you'd ever see PHP.ini anyway.
Ask your ISP though, see what they say - probably won't be very helpful, but
just sending a quick e-mail can't hurt, and could maybe be useful if you get
someone who knows something to respond.

David
Jul 16 '05 #10

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

Similar topics

4
2916
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just upload files, like this: copy ($myfile, $uploadfolder . "/" . $myfile_name); Everything works fine, it can process large files and everything, but i need to make sure that people only upload pictures, so i change
15
3206
by: Simon | last post by:
I would like to create a very basic file upload add image form to add to my web site and to keep them in a "tmp" directory within my web hosting file manager once uploaded. I understand the basic html for the form and the basic php scripting but the fine details ie method post etc needs help also at this stage I dont want to involve mysql data base. were should I start.
2
3921
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
13
4297
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
2
3429
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage() fileitem = form if fileitem.file: # It's an uploaded file; count lines
7
3182
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file" name="file_1" size=46 /><input type=submit /> so, after adding a few files, the input fields look like this:
2
7645
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before...
1
5446
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one group get automatically re-directed after uploading. However, this member group never gets the benefit of knowing if they've uploaded an incorrect file size or incorrect file extension. Members from the second group do see the "exceeds max file...
6
3830
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 network should be able to connect to the database and run queries on the database or upload new music that does not yet exist on the database. The uploaded file's name should be in the following format: ARTIST - TITLE.mp3. I have the code to upload images,...
7
7147
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and Silverlight 2.0. To get these tools please visit this page Get Started : The Official Microsoft Silverlight Site and follow Step 1. Occasionally you find the need to have users upload multiple files at once. You could use multiple FileUpload...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.