Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Uploading images with PHP

LEGEND ,
Sep 04, 2006 Sep 04, 2006
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
==================




TOPICS
Server side applications
627
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 04, 2006 Sep 04, 2006
i am not getting that error on my server. what version of php are you using?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 04, 2006 Sep 04, 2006
two other things:
I dont use it but they say that file uploads with php can fail with ie & ssl
http://support.microsoft.com/?kbid=889334
the result can be an empty $_FILES array. have you tried
print_r($_FILES) just to try to pinpoint the source of the error?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 2006
5....

--
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
==================


"digitalus media" <webforumsuser@macromedia.com> wrote in message
news:edi501$ooa$1@forums.macromedia.com...
>i am not getting that error on my server. what version of php are you
>using?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 2006
That's surely the problem - the array is empty. Hmmm - how is that
possible?

--
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
==================


"digitalus media" <webforumsuser@macromedia.com> wrote in message
news:edi5fm$pa8$1@forums.macromedia.com...
> two other things:
> I dont use it but they say that file uploads with php can fail with ie &
> ssl
> http://support.microsoft.com/?kbid=889334
> the result can be an empty $_FILES array. have you tried
> print_r($_FILES) just to try to pinpoint the source of the error?
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 04, 2006 Sep 04, 2006
have you tried it with register globals turned on?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 2006
No. And, I don't want to. It should work this way, no?

--
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
==================


"digitalus media" <webforumsuser@macromedia.com> wrote in message
news:edi8qc$t17$1@forums.macromedia.com...
> have you tried it with register globals turned on?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 2006
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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 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/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 04, 2006 Sep 04, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 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/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2006 Sep 04, 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/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 04, 2006 Sep 04, 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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2006 Sep 05, 2006
digitalus media wrote:
> the $_FILES array is the response from the server after
> it is uploaded right?

Yes, the $_FILES array contains details of what has been uploaded,
whether the upload was successful, and the location of the temporary
file. The important thing to understand is that the temporary file is
discarded if you don't move it to a permanent location before the end of
the script.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2006 Sep 05, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2006 Sep 05, 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/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2006 Sep 05, 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/
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2006 Sep 05, 2006

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

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

Tom


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2006 Sep 05, 2006
LATEST
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
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines