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

accessing array data inside of an array

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
Nov 18 '07 #1
9 1416
On Nov 18, 10:13 am, bill <nob...@spamcop.netwrote:
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']
Nov 18 '07 #2
ZeldorBlat wrote:
On Nov 18, 10:13 am, bill <nob...@spamcop.netwrote:
>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
Nov 18 '07 #3
On Sun, 18 Nov 2007 16:47:17 +0100, bill <no****@spamcop.netwrote:
ZeldorBlat wrote:
>On Nov 18, 10:13 am, bill <nob...@spamcop.netwrote:
>>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.pa rsing>

echo "<br />pic_name = {$_FILES['picture']['name']}";
--
Rik Wasmus
Nov 18 '07 #4
bill wrote:
echo "<br />pic_name = $_FILES[picture][name]";
echo "<br />pic_name = {$_FILES[picture][name]}";

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 12 days, 2 min.]
[Now Playing: ./orson/bright_idea/03_-_happiness.ogg.]

USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/
Nov 18 '07 #5
On Sun, 18 Nov 2007 18:05:32 +0100, Toby A Inkster
<us**********@tobyinkster.co.ukwrote:
bill wrote:
>echo "<br />pic_name = $_FILES[picture][name]";

echo "<br />pic_name = {$_FILES[picture][name]}";
define('picture','oops');
define('name','wrong');
--
Rik Wasmus
Nov 19 '07 #6
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.

Besides which, it's not normal to define lower-case constants.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 12 days, 15:31.]

USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/
Nov 19 '07 #7
Toby A Inkster wrote:
Besides which, it's not normal to define lower-case constants.
And people who do so are not normal. They have something wrong with them
in their head. Just thinking about the idea makes me feel icky.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 12 days, 17:44.]

USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/
Nov 19 '07 #8
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.

bill
Nov 19 '07 #9
On Mon, 19 Nov 2007 09:34:23 +0100, Toby A Inkster
<us**********@tobyinkster.co.ukwrote:
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
Nov 19 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Demian | last post by:
Hi, I developed an OCX in VC++, wich takes a VARIANT as parameter and return a Long as the result of the operation. This VARIANT cames from a client VB6.0 wich send an array of Byte as a VARIANT,...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
5
by: pt | last post by:
Hi, i am wonderng what is faster according to accessing speed to read these data structure from the disk in c/c++ including alignment handling if we access it on little endian system 32 bits...
4
by: pt | last post by:
Hi, i am wonderng what is faster according to accessing speed to read these data structure from the disk in c/c++ including alignment handling if we access it on little endian system 32 bits...
10
by: Chris | last post by:
Hi, I'd like to be able to access an attribute of a particular Python object as fast as possible from some C code. I wondered if using __slots__ to store the attribute would allow me to do...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.