473,803 Members | 2,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

58 New Member
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 2103
pbmods
5,821 Recognized Expert Expert
Changed thread title to better match contents.
Jun 5 '07 #2
Motoma
3,237 Recognized Expert Specialist
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 New Member
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 Recognized Expert Specialist
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 New Member
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 New Member
if(isset($_POST['submit'])) { alone also work
the submit button is named submit
Jun 5 '07 #7
Motoma
3,237 Recognized Expert Specialist
Do a print_r on your FILES array and see what the size is showing.
Jun 5 '07 #8
Jankie
58 New Member
Thank you Motoma for taking the time to look at it
I'll try your suggestion,seem s 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 Recognized Expert Specialist
Thank you Motoma for taking the time to look at it
I'll try your suggestion,seem s 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
7727
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 again without GD to fix the problem, to go back to what I had before, but $_FILES is always empty. I can't imagine that I'm doing something so out of the ordinary, and yet I'm unable to google for someone with the same problem. I am running...
4
3456
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 code. The file upload system is working fine if the file is smaller than the defined size, but if it's larger, then both the _POST and _FILES arrays are completely empty:
3
3930
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
3716
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
3491
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 it to a directory and store the path to the file in the db, in addition to storing other text from other fields in the form. Then I will get that path using PHP to display the image file in a browser. First things first, I'm having difficulty...
3
3301
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 it's mail () function to send the mail. However, as I got more into that topic I realized that one should be really concerned about the validation part to prevent spam abuse. There are shiploads of 'mail scripts' available with each of them has...
1
3163
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 to test with. I also tried it on a remote linux server, though in that case I'm not sure what the s config settings where, except that it does have PHP and I get the same results. Are there any releevant apache settings ? I have not come...
3
2249
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 check if the user entered something or not as this isn't mandatory. Here's an excerpt of the relavent code: if (isset($_POST))
5
2583
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" and if I select accept, I receive a message that say: The news article "headline" are posted into the database.
0
9703
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
9566
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
10555
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
9127
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...
1
7607
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
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
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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
3
2974
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.