Skip to main content
Inspiring
September 4, 2006
Question

Uploading images with PHP

  • September 4, 2006
  • 17 replies
  • 625 views
I have the following markup on my page -

<?php
if(isset($_POST['Submit'])) {
foreach ($_FILES["drawings"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["drawings"]["tmp_name"][$key];
$drawingname = $_FILES["drawings"]["name"][$key];
$userName = $row_rsUser['fuserName'];
//echo($tmp_name."-".$drawingname."-".$userName);
move_uploaded_file($tmp_name,
"../images/users/$userName/$drawingname");
}
}
}
?>
...
<form id="form1" name="form1" method="post" action=""
enctype="multipart/form-data">
<p>Upload New Images:</p>
<p>
<input type="file" name="drawings[]" />
</p>
<p>
<input type="file" name="drawings[]" />
</p>
<p>
<input type="file" name="drawings[]" />
</p>
<input type="submit" name="Submit" value="Send" />
</form>

And when I submit, I get this -

Warning: Invalid argument supplied for foreach() in
W:\Webspace\resadmin\madison\madisonconcrete.com\www\manage\m_users_update.php
on line 77

I'm tapped - any ideas?


--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================




This topic has been closed for replies.

17 replies

Inspiring
September 5, 2006
In this case, I definitely needed to remember it! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NOSPAM.basic-drumbeat.com> wrote in message
news:edjub1$p6c$1@forums.macromedia.com...
>
>> I encountered this before, and forgot to remember it! 8)
>
> I prefer to think of it as remembering to forget it.
>
> Tom
>


Inspiring
September 5, 2006

> I encountered this before, and forgot to remember it! 8)

I prefer to think of it as remembering to forget it.

Tom


Inspiring
September 5, 2006
Got it. The problem was that I was trying to send images from a networked
box rather than from the box on which I was testing. When the image is
truly local, it works! YIPPEE! I encountered this before, and forgot to
remember it! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:edjl40$f0k$1@forums.macromedia.com...
> OK - thanks. Hmmm....
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "David Powers" <david@example.com> wrote in message
> news:edjfg9$91c$1@forums.macromedia.com...
>> Murray *ACE* wrote:
>>> I'm puzzled by the empty array - it should be filled before any upload
>>> takes place, right?
>>
>> No, it's the result of the upload. I have tested the script you posted
>> here, and it works. There must be something else that is getting in the
>> way.
>>
>> --
>> David Powers
>> Adobe Community Expert
>> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
>> http://foundationphp.com/
>
>


Inspiring
September 5, 2006
OK - thanks. Hmmm....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:edjfg9$91c$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> I'm puzzled by the empty array - it should be filled before any upload
>> takes place, right?
>
> No, it's the result of the upload. I have tested the script you posted
> here, and it works. There must be something else that is getting in the
> way.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
September 5, 2006
Murray *ACE* wrote:
> I'm puzzled by the empty array -
> it should be filled before any upload takes place, right?

No, it's the result of the upload. I have tested the script you posted
here, and it works. There must be something else that is getting in the way.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
September 5, 2006
Nope - neither of those apply, but thanks. I'm puzzled by the empty array -
it should be filled before any upload takes place, right?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:edidqe$4q5$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> So toss me a bone here, Mr. PHP! 8)
>
> Well, the bone I tossed you is to check the file_uploads setting with
> phpinfo(). Another possibility is that the files are larger than permitted
> by upload_max_filesize.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


September 5, 2006
i am not sure on this, but doesn't the file get uploaded to the temp directory first? i allways assumed this because it loads the $_FILES array with the temp name on the server, so the $_FILES array is the response from the server after it is uploaded right?
Inspiring
September 5, 2006
It's not, I know because my protoype page,
http://66.165.96.216/uploadtest.php works fine, as does another page I built
for the admin backend that uploads and resizes into 2 different thumbs.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:edi9t0$qn$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> That's surely the problem - the array is empty. Hmmm - how is that
>> possible?
>
> Are you testing locally or on a remote server? If the latter, what is the
> value of file_uploads when you run phpinfo()? File uploads may be turned
> off on the server.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
September 4, 2006
Murray *ACE* wrote:
> So toss me a bone here, Mr. PHP! 8)

Well, the bone I tossed you is to check the file_uploads setting with
phpinfo(). Another possibility is that the files are larger than
permitted by upload_max_filesize.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
September 4, 2006
Murray *ACE* wrote:
> That's surely the problem - the array is empty. Hmmm - how is that
> possible?

Are you testing locally or on a remote server? If the latter, what is
the value of file_uploads when you run phpinfo()? File uploads may be
turned off on the server.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
September 4, 2006
yeah, i do not rely on globals either. on php.net they did mention that some parts of the files array ar enot available with register globals off. it was a user comment, so maybe they were incorrect. i have not had issues with the same script on my server with register globals off.
Inspiring
September 4, 2006
So toss me a bone here, Mr. PHP! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:edi9g1$f0$1@forums.macromedia.com...
> digitalus media wrote:
>> have you tried it with register globals turned on?
>
> That will have no effect. The $_FILES array is one of the superglobal
> arrays designed to eliminate the massive security hole created by
> register_globals. Although some hosting companies still turn
> register_globals on, anyone who relies on register_globals is living on
> borrowed time. The default setting for the past four years has been for
> register_globals to be off, and it has been removed entirely from the
> forthcoming PHP 6.
>
> If you have any scripts that rely on register_globals, bring them up to
> date now - before it's too late.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/