 |
|
 |
|
Next: some thoughts on OOW 2007
|
| Author |
Message |
External

Since: Nov 24, 2006 Posts: 17
|
(Msg. 1) Posted: Sun Nov 18, 2007 10:13 am
Post subject: accessing array data inside of an array Archived from groups: comp>lang>php (more info?)
|
|
|
I want to extract the name of the photo uploaded.
print_r of $_FILES yields:
Files: Array ( [picture] => Array ( [name] =>
DSC_1802-saoirse-riona.jpg [type] => image/jpeg [tmp_name] =>
/tmp/phpJTspHZ [error] => 0 [size] => 76096 ) )
so we have an array with one element, picture, that contains an
array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
I get the correct value when I:
$pic_name = $_FILES['picture']['name'];
echo $pic_name
however when I use:
echo "<br />pic_name = $_FILES[picture][name]";
I get:
pic_name = Array[name]
Why does the echo with the array reference not work while the
assignment does ?
bill >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
External

Since: Apr 17, 2007 Posts: 44
|
(Msg. 2) Posted: Sun Nov 18, 2007 10:14 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Nov 18, 10:13 am, bill wrote:
> I want to extract the name of the photo uploaded.
>
> print_r of $_FILES yields:
> Files: Array ( [picture] => Array ( [name] =>
> DSC_1802-saoirse-riona.jpg [type] => image/jpeg [tmp_name] =>
> /tmp/phpJTspHZ [error] => 0 [size] => 76096 ) )
>
> so we have an array with one element, picture, that contains an
> array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
>
> I get the correct value when I:
> $pic_name = $_FILES['picture']['name'];
> echo $pic_name
>
> however when I use:
>
> echo "<br />pic_name = $_FILES[picture][name]";
>
> I get:
> pic_name = Array[name]
>
> Why does the echo with the array reference not work while the
> assignment does ?
>
> bill
Put quotes around your array keys:
$_FILES['picture']['name'] >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
External

Since: Nov 24, 2006 Posts: 17
|
(Msg. 3) Posted: Sun Nov 18, 2007 10:47 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
ZeldorBlat wrote:
> On Nov 18, 10:13 am, bill wrote:
>> I want to extract the name of the photo uploaded.
>>
>> print_r of $_FILES yields:
>> Files: Array ( [picture] => Array ( [name] =>
>> DSC_1802-saoirse-riona.jpg [type] => image/jpeg [tmp_name] =>
>> /tmp/phpJTspHZ [error] => 0 [size] => 76096 ) )
>>
>> so we have an array with one element, picture, that contains an
>> array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
>>
>> I get the correct value when I:
>> $pic_name = $_FILES['picture']['name'];
>> echo $pic_name
>>
>> however when I use:
>>
>> echo "<br />pic_name = $_FILES[picture][name]";
>>
>> I get:
>> pic_name = Array[name]
>>
>> Why does the echo with the array reference not work while the
>> assignment does ?
>>
>> bill
>
> Put quotes around your array keys:
>
> $_FILES['picture']['name']
That, unfortunately, generates the dreaded:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in...
bill >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
External

Since: Sep 02, 2007 Posts: 210
|
(Msg. 4) Posted: Sun Nov 18, 2007 4:00 pm
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Sun, 18 Nov 2007 16:47:17 +0100, bill wrote:
> ZeldorBlat wrote:
>> On Nov 18, 10:13 am, bill wrote:
>>> I want to extract the name of the photo uploaded.
>>>
>>> print_r of $_FILES yields:
>>> Files: Array ( [picture] => Array ( [name] =>
>>> DSC_1802-saoirse-riona.jpg [type] => image/jpeg [tmp_name] =>
>>> /tmp/phpJTspHZ [error] => 0 [size] => 76096 ) )
>>>
>>> so we have an array with one element, picture, that contains an
>>> array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
>>>
>>> I get the correct value when I:
>>> $pic_name = $_FILES['picture']['name'];
>>> echo $pic_name
>>>
>>> however when I use:
>>>
>>> echo "<br />pic_name = $_FILES[picture][name]";
>>>
>>> I get:
>>> pic_name = Array[name]
>>>
>>> Why does the echo with the array reference not work while the
>>> assignment does ?
>>>
>>> bill
>> Put quotes around your array keys:
>> $_FILES['picture']['name']
>
> That, unfortunately, generates the dreaded:
> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> expecting T_STRING or T_VARIABLE or T_NUM_STRING in...
Look at complex (curly) syntax:
<http://nl2.php.net/manual/en/language.types.string.php#language.types.string.parsing>
echo "<br />pic_name = {$_FILES['picture']['name']}";
--
Rik Wasmus >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
External

Since: Nov 13, 2007 Posts: 29
|
(Msg. 5) Posted: Sun Nov 18, 2007 4:00 pm
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Sep 02, 2007 Posts: 210
|
(Msg. 6) Posted: Mon Nov 19, 2007 1:59 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Nov 13, 2007 Posts: 29
|
(Msg. 7) Posted: Mon Nov 19, 2007 6:00 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Nov 24, 2006 Posts: 17
|
(Msg. 8) Posted: Mon Nov 19, 2007 7:23 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Nov 13, 2007 Posts: 29
|
(Msg. 9) Posted: Mon Nov 19, 2007 7:59 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Sep 02, 2007 Posts: 210
|
(Msg. 10) Posted: Mon Nov 19, 2007 1:59 pm
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Mon, 19 Nov 2007 09:34:23 +0100, Toby A Inkster
wrote:
> Rik Wasmus wrote:
>> define('picture','oops');
>> define('name','wrong');
>
> I know, I know, but I wanted to keep the code as similar as possible to
> the OP's.
Then again, why correct just one mistake and not the other?
> Besides which, it's not normal to define lower-case constants.
Very true indeed.
--
Rik Wasmus >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
External

Since: Sep 02, 2007 Posts: 210
|
(Msg. 11) Posted: Mon Nov 19, 2007 1:59 pm
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Mon, 19 Nov 2007 13:23:08 +0100, bill wrote:
> Toby A Inkster wrote:
>> bill wrote:
>>
>>> echo "<br />pic_name = $_FILES[picture][name]";
>> echo "<br />pic_name = {$_FILES[picture][name]}";
>>
> Rik and Toby
> Thanks, something new to learn.
Hmm, now I think about it: offcourse you never ever change the $_FILES
array yourself, you just use it's information. There is no way you should
echo user supplied strings directly to the page. At least use
htmlentities() on them before displaying them, or you're vulnerable to so
called XSS attack.
See <http://en.wikipedia.org/wiki/Cross_site_scripting>, Type 1 (and
possibly 2 depending on further processing).
--
Rik Wasmus >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
External

Since: Nov 24, 2006 Posts: 17
|
(Msg. 12) Posted: Tue Nov 20, 2007 7:19 am
Post subject: Re: accessing array data inside of an array [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Rik Wasmus wrote:
> On Mon, 19 Nov 2007 13:23:08 +0100, bill wrote:
>
>> Toby A Inkster wrote:
>>> bill wrote:
>>>
>>>> echo "<br />pic_name = $_FILES[picture][name]";
>>> echo "<br />pic_name = {$_FILES[picture][name]}";
>>>
>> Rik and Toby
>> Thanks, something new to learn.
>
> Hmm, now I think about it: offcourse you never ever change the $_FILES
> array yourself, you just use it's information. There is no way you
> should echo user supplied strings directly to the page. At least use
> htmlentities() on them before displaying them, or you're vulnerable to
> so called XSS attack.
just for debugging. Not a live application
>
> See <http://en.wikipedia.org/wiki/Cross_site_scripting>, Type 1 (and
> possibly 2 depending on further processing).
thanks for the reminder however
bill >> Stay informed about: accessing array data inside of an array |
|
| Back to top |
|
 |  |
| Related Topics: | Incoming data into array? - Hi, I'm opening a remote file on a regular basis, the data is in the following format and has a line feed of "0D 0A". The spaces are 20 in hex mode. 2006-07-26 22:00:03.000000 4.370996 51.656616 2006-07-26 22:00:03.000000 2.599964 49.286836 ...
Form Data -> Variables or an Array? - Hi I need help! Forgive me I am a PHP newbie. I have a small script that enables me to send a form from an HTML page. I want to use the HTML formatted form because the design of my website is complex, and I don't want to have to mess around with..
Array - Hi Can you help me sort my array on salary $Person[$personid][salary] e.g. $Person[1][20000] $Person[2][5000] $Person[3][15000] $Person[4][10000] to $Person[2][5000] $Person[4][10000] $Person[3][15000] $Person[1][20000] Thanx
SUM of array - I want to get the sum of the array key values. ex: $key1=>10, $key2=>15, $key3=>5 I want variable $sum = 30. any solution?
array() VS Array() - which one is recommend? seems they perform the same thing... regards, howa |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|