473,387 Members | 1,722 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,387 software developers and data experts.

Is $_FILES more secure than $_POST? Which should I use?

58
Greetings !
i hope someone can give me some insights as to what upload method to use of these and if any comparison
I found that :
if (isset($_FILES['userfile'])) {

works for me in some applications where:
if(isset($_POST['submit']))
does not

How secure is the first method ?

Thank you very much in advance !
Jun 5 '07 #1
9 2079
pbmods
5,821 Expert 4TB
Changed thread title to better match contents.
Jun 5 '07 #2
Motoma
3,237 Expert 2GB
Greetings !
i hope someone can give me some insights as to what upload method to use of these and if any comparison
I found that :
if (isset($_FILES['userfile'])) {

works for me in some applications where:
if(isset($_POST['submit']))
does not

How secure is the first method ?

Thank you very much in advance !
I think that will only work when a file has been uploaded. I think the only reason why the second one will not work is because you have titled the submit button differently. Remember, the POST array is case sensitive!
Jun 5 '07 #3
Jankie
58
Well,if(isset($_POST['submit']) DOES work

but if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0) {
does not work for me in conjunction with:
if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK) {
Jun 5 '07 #4
Motoma
3,237 Expert 2GB
I don't know what you are looking for. Perhaps you could carefully word a question that accurately expresses the difficulties you are having as well as alludes to what you need for information from me. It also helps if you post the relevant segments of code, and delineate what is happening, what isn't happening, and what you want to happen.
Jun 5 '07 #5
Jankie
58
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
  3.     if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK) {
  4.         $tmpName = $_FILES['userfile']['tmp_name'];
  5.         $fileName = $_FILES['userfile']['name'];
  6. $uploaddir = 'uploads/';
  7. $uploadfile = $uploaddir.basename($_FILES['userfile']['name']);
  8.    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
  9.             echo 'File Uploaded!';
  10.         } 
  11. else {
  12.             echo 'Upload failed.'; 
  13.  }
  14.     }
  15.  elseif ($_FILES['userfile']['error'] == UPLOAD_ERR_FORM_SIZE) {
  16.         echo 'File exceeds allowed upload file size.';
  17.   }
  18. ?>
  19. ---corretly set Form here----
  20. if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0) does not work but
  21.  
  22. if (isset($_FILES['userfile'])) {   does
  23.  
Jun 5 '07 #6
Jankie
58
if(isset($_POST['submit'])) { alone also work
the submit button is named submit
Jun 5 '07 #7
Motoma
3,237 Expert 2GB
Do a print_r on your FILES array and see what the size is showing.
Jun 5 '07 #8
Jankie
58
Thank you Motoma for taking the time to look at it
I'll try your suggestion,seems the right direction. I just want the :
&& $_FILES['userfile']['size'] > 0) part to ensure no 0 byte file is uploaded(for security reasons) instead of inserting another if/else statement.
Jun 5 '07 #9
Motoma
3,237 Expert 2GB
Thank you Motoma for taking the time to look at it
I'll try your suggestion,seems the right direction. I just want the :
&& $_FILES['userfile']['size'] > 0) part to ensure no 0 byte file is uploaded(for security reasons) instead of inserting another if/else statement.
Anytime. Post back and let me know if that gave any insight into the problem.
Jun 5 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mrbog | last post by:
All I did was recompile my PHP 4.3.4 with the included GD and now my $_FILES is perpetually empty. My php app is identical, I haven't changed it at all since recompiling. I tried recompiling...
4
by: Ian.H | last post by:
Hi all, Uploading of files.. AFAIU from the manual, if a file is larger than the size defined in the form or larger than upload_max_filesize in php.ini, that _FILES should hold an INT error...
3
by: Bob Bedford | last post by:
I'm passing the code from $_POST to $_GET. I've a page upload using $_FILES. when the page was in $_POST, it worked fine, but now, in $_GET, the $_FILES is empty. any idea ?
2
by: chris | last post by:
Can someone else see immediately why this script: <html> <body> <?php error_reporting(~E_ALL); print_r($_FILES); print_r($_POST);
8
by: mpar612 | last post by:
Hello, I am a newbie to PHP, MySQL. I am trying to create a basic file upload form. I want to get that working and then I want to integrate that into a form that will rename the file and save...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
1
by: wbsurfver | last post by:
I'm trying to figure out why I can't upload a file in php. I'm trying it locally on a windows XP machine running Apache 2.2 and PHP 5.2.1. That is I am running the browser/server on same machine...
3
by: skulkrinbait | last post by:
I've a HTML form that allows a user to specify the location to upload a file from: <p><label for = 'file'>Upload Graphics : <input type='file' name='imagefile' /></label></p> I then want to...
5
by: Karl | last post by:
Hello again. I have a form for posting news articles. Form one is the "register" form. Then I go to the preview form were I can select edit or accept If I select edit, I got the "edit form"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.