PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 10th, 2013, 02:01 PM
Aganju Aganju is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 8 Aganju New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 19 m 51 sec
Reputation Power: 0
PHP-General - Issue with $_FILES

Hi,

I have a strange issue in a script for uploading images.
I have a page to modify products.
The logic function of the page is that if I do not select the modification of the image product, the script "skip" the code to upload and continues with the rest of the script.
I put a check on $ _FILES after sending the form, but the result is
$ _FILES ['FleImage'] ['name'] is always NOT empty.
but print_r ($ _FILES) say to me that array is empty.

PHP Code:
echo"<pre>"
print_r($_FILES); 
echo
"</pre>"

$name $_FILES['fleImage']['name']; 
if (empty(
$name)) { echo "is empty"

else 

echo 
"is not empty";} 


then i created a simple test page with forms and controls equal to the original page:
PHP Code:
<!DOCTYPE html
<
html
<
head
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
</
head
<
body

<
form action="" method="post" enctype="multipart/form-data" name="prova"
<
input name="fleImage" type="file" id="fleImage" class="box" multiple="multiple"
<
input name="modify" type="submit" value="Modify Product"
</
form

<?
php echo"<pre>"
print_r($_FILES); 
echo
"</pre>"

$name $_FILES['fleImage']['name']; 
if (empty(
$name)) 

echo 
"is empty"
} else {
echo 
"is not empty";} ?> 

</body> 
</html> 


and this example works correctly!
Why?

Reply With Quote
  #2  
Old February 10th, 2013, 02:48 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 7 h 28 m 24 sec
Reputation Power: 581
Use '!isset' rather than 'empty'.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old February 10th, 2013, 03:12 PM
Aganju Aganju is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 8 Aganju New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 19 m 51 sec
Reputation Power: 0
hi gw1500se,

I used !isset($name) but does not work..

Selecting an image:

Code:
Array ( 
[fleImage] => Array 
( [name] => Array ( [0] => IMG_0219.JPG ) 
[type] => Array 
( [0] => image/jpeg ) 
[tmp_name] => Array 
( [0] => E:\xampp\tmp\php2D01.tmp ) 
[error] => Array ( [0] => 0 ) 
[size] => Array ( [0] => 3311146 ) 
) 
)

result: is isset

NOT Selecting an image:

Code:
Array ( 
[fleImage] => Array 
( [name] => Array ( [0] => )
 [type] => Array ( [0] => ) 
[tmp_name] => Array ( [0] => )
 [error] => Array ( [0] => 4 ) 
[size] => Array ( [0] => 0 ) 
) 
) 


result: is isset

Reply With Quote
  #4  
Old February 10th, 2013, 03:51 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 7 h 28 m 24 sec
Reputation Power: 581
Are you using it on $_FILES?

Reply With Quote
  #5  
Old February 10th, 2013, 03:56 PM
Aganju Aganju is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 8 Aganju New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 19 m 51 sec
Reputation Power: 0
yes

PHP Code:
 $name $_FILES['fleImage']['name']; 
if (!isset(
$name)) {
.... 

Reply With Quote
  #6  
Old February 10th, 2013, 06:02 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 7 h 28 m 24 sec
Reputation Power: 581
Use it to check $_FILES before setting $name.

Reply With Quote
  #7  
Old February 11th, 2013, 02:33 PM
Aganju Aganju is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 8 Aganju New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 19 m 51 sec
Reputation Power: 0
Does not work ..
I try to summarize the entire operation:

form
Code:
<form action="processProduct.php?action=modifyProduct&productId=<?php echo $productId; ?>" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">


At the submit i send everything to the file processProduct.php

PHP Code:
 $action = isset($_GET['action']) ? $_GET['action'] : '';
 switch (
$action) {
case 
'modifyProduct' :
        
test();
        break;
}

function 
test()
{


echo
"<pre>";
print_r($_FILES);
echo
"</pre>";

if (!isset(
$_FILES['fleImage']['name'])) {

echo 
"is empty"
} else {
echo 
"is not empty";
}
 } 


and that's it ... but it does not work

I do not understand why the test page I posted beginning of this thread works perfectly and this test do not work...

Reply With Quote
  #8  
Old February 11th, 2013, 02:44 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 7 h 28 m 24 sec
Reputation Power: 581
What part does not work?

Reply With Quote
  #9  
Old February 11th, 2013, 02:58 PM
Aganju Aganju is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 8 Aganju New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 19 m 51 sec
Reputation Power: 0
The control on $_FILES!

i used empty() and !isset()
i send data from the form with and without images (checked with print_r ) but result is always "is not empty"!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Issue with $_FILES

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap