The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: , ,

Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-16-2007, 01:13 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Icon9 PHP File Upload

PHP Code:
<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo 
"Error: " $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo 
"Upload: " $_FILES["file"]["name"] . "<br />";
  echo 
"Type: " $_FILES["file"]["type"] . "<br />";
  echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo 
"Stored in: " $_FILES["file"]["tmp_name"];
  }
?>
I'm confused with the conditional inside the if(...)

[php]$_FILES["file"]["error"] // the error code resulting from the file upload-/PHP]

I still don't understand that line... can anybody help me out with this? How can PHP check if there's an error if there's no $_FILES["file"]["error"] that's instantiated to be 0 or > 1 ???? I'm confused

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #2 (permalink)  
Old 06-16-2007, 01:22 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee is just really niceLee is just really niceLee is just really niceLee is just really nice
From what i gather,
PHP Code:
$_FILES["file"]["error"] > 
Means that if there are more than 0 errors, so theres an error in the file then
PHP Code:
  echo "Error: " $_FILES["file"]["error"] . "<br />"
Show the error.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 06-16-2007, 01:30 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by Lee View Post
From what i gather,
PHP Code:
$_FILES["file"]["error"] > 
Means that if there are more than 0 errors, so theres an error in the file then
PHP Code:
  echo "Error: " $_FILES["file"]["error"] . "<br />"
Show the error.
what do you mean with error in the file? It's checking error WITHIN the file, or error within your PHP codes?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #4 (permalink)  
Old 06-16-2007, 01:59 PM
Nutter Nutter is offline
Novice
Join Date: Jun 2007
Posts: 22
iTrader: (0)
Nutter is on a distinguished road
You've got a form with
Code:
<input type="file" name="file">
that submits to your php code. The $_FILES['file']['error'] will contain a number based on whether there was an error. 0 is no error. Look at www.php.net/features.file-upload . It's very clear on how to do this.

__________________
- Ryan
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 06-16-2007, 02:17 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
The $_FILES['file']['error'] will contain a number based on whether there was an error. 0 is no error.
I understand that, but I'm just wondering to what exactly this PHP code is checking by putting $_FILES['file']['error'] within the IF conditional statement for example:

PHP Code:
if ($x 0) {
    echo 
"Hello";
} else {
    echo 
"World";

I understand exactly what the code above does, which is checking variable $x whther it's bigger or less than 0... so what's $_FILES['file']['error'] is checking? I also understand that it's checking whether there's an error or not, but where? if there's an error within PHP? but where's the error? it's impossible to have an error, since there's nothing to be checked earlier please give me some example, prob help me better thx a lot guys...

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #6 (permalink)  
Old 06-16-2007, 02:17 PM
Blood08's Avatar
Blood08 Blood08 is offline
Jr. Programmer
Awards Showcase
Quality Tutorial Quality Tutorial 
Total Awards: 2
Join Date: Jun 2007
Location: Source Code
Posts: 98
iTrader: (0)
Blood08 is on a distinguished road
from what I am getting from it is that it is checking for errors in the file type, size, ect... and errors with in the php script,,, as far as I can see

Edit:
Hhmmm well forget this post I posted at the sime time the post above was posted

__________________
Fersk Webmasters' Forum
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #7 (permalink)  
Old 06-16-2007, 02:25 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by Blood08 View Post
from what I am getting from it is that it is checking for errors in the file type, size
do you even know PHP upload before you're talking about these? If that's the only line that can check all of those, then what's the point of having $_FILES['file']['size'] and $_FILES['file']['type'] ???

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #8 (permalink)  
Old 06-16-2007, 02:29 PM
Blood08's Avatar
Blood08 Blood08 is offline
Jr. Programmer
Awards Showcase
Quality Tutorial Quality Tutorial 
Total Awards: 2
Join Date: Jun 2007
Location: Source Code
Posts: 98
iTrader: (0)
Blood08 is on a distinguished road
The only thing I know about uploading is at the following:
PHP File Upload

just thought I would state my thoughts...

__________________
Fersk Webmasters' Forum
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #9 (permalink)  
Old 06-16-2007, 02:39 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by Blood08 View Post
The only thing I know about uploading is at the following:
PHP File Upload

just thought I would state my thoughts...

that's because you don't know it, that's why you said that's the only thing that you know about uploading. I'm giving you example from that website too.. omg...

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #10 (permalink)  
Old 06-16-2007, 03:27 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee is just really niceLee is just really niceLee is just really niceLee is just really nice
I am 99% sure that line checks for an error within the file, for PHP to do something as its server side the file must first be uploaded, if the file is corrupt it will say that theres an error in the file and why that is so, otherwise its going to show the statistics of the file such as its name/size etc...

The name and size and other things like that can be used to make restrictions or checks, like when a file is uploaded if you only want to allow a certain size then you would use that value to compare against the size you want and choose where to go from there.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 09:41 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50