473,788 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1428
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#lang uage.types.stri ng.parsing>

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**********@t obyinkster.co.u kwrote:
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**********@t obyinkster.co.u kwrote:
Rik Wasmus wrote:
>define('pictur e','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
4807
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, so acomplish Autonmation std. I need to access the array inside the variant to load an user-defined struct with it. To do this I used the myvariant->parray.pvData but it didn't work. It seems that the data wasn't there... I tried with...
6
2746
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 called "form1", and I have selects called "PORTA", "PORTB" ... etc...
5
575
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 system + OS e.g. Windows, Linux, WinCE. I am not quite sure about the alignment of the memory.... soln. 1: should be faster, I am not sure. idx size (bytes) 1 4
4
2900
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 system + OS e.g. Windows, Linux, WinCE. I am not quite sure about the alignment of the memory.... soln. 1: should be faster, I am not sure. idx size (bytes) 1 4
10
1615
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 this in a faster way. The reason I'd like to do this is because I need to access the attribute inside a loop within some C code, and I find that the
0
9498
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
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8995
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
7519
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
6750
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
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
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
2897
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.