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

Uploading/ Inserting image file URL

Engaged ,
Dec 04, 2006 Dec 04, 2006
running on LAMP.

After finding out that it is best to 'store' images as an address url link rather than in binary in the database itself, I have re-configured the filed definition to VARCHAR and entered some test addresses.

The I have put in a 'logos' directory under the root which will hold all the image files themselves.

I have then managed to get the results php pages to take the url address and display it as an image..

Going great so far.... Here's the crunch..

For both insert and update pages, I have used a form file field which browses the location and inserts it into the field - this does return an address into the field but when it submits, it doesn't save the image data. (Everything else does update OK). In fact, it seems to overwrite with a null value.

I have checked the insert and update behaviours but cannot find where I'm going wrong.

Field code:
<input name="LOGO" type="file" id="LOGO">

Update/Insert code:
GetSQLValueString($HTTP_POST_VARS['LOGO'], "text"),
TOPICS
Server side applications
1.1K
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

correct answers 1 Correct answer

LEGEND , Dec 06, 2006 Dec 06, 2006
On Wed, 6 Dec 2006 17:36:13 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>OMG - didn't realise - sorry...

No worries.

I have done a demo for you. It mimics (as far as I can) your database
table and I have pre-loaded the form with test data to save a lot of
typing. Use it to upload logos (jpg or gif format) and then view the
inserted records (and logos using the link provided). I have zipped
the two files and my test database table for your perusal. Note that
the fo...
Translate
LEGEND ,
Dec 04, 2006 Dec 04, 2006
On Mon, 4 Dec 2006 12:41:33 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

> Going great so far.... Here's the crunch..
>
> For both insert and update pages, I have used a form file field which browses
>the location and inserts it into the field - this does return an address into
>the field but when it submits, it doesn't save the image data. (Everything else
>does update OK). In fact, it seems to overwrite with a null value.
>
> I have checked the insert and update behaviours but cannot find where I'm
>going wrong.
>
> Field code:
> <input name="LOGO" type="file" id="LOGO">
>
> Update/Insert code:
> GetSQLValueString($HTTP_POST_VARS['LOGO'], "text"),

The problem is that the information you want is not stored in the
$_POST array but the $_FILES array. To get at the name of the file in
the file field you need to use $_FILES['LOGO']['name'] instead of
$_POST['LOGO']

--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 05, 2006 Dec 05, 2006
Steve

Without sounding ignorant, do you mean:

GetSQLValueString($_FILES['LOGO'],['Logo'],"text")

rather than

GetSQLValueString($HTTP_POST_VARS['LOGO'], "text")

I couldn't find any exact reference to "$_POST['LOGO']" so am at a bit of a loss...
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 ,
Dec 05, 2006 Dec 05, 2006
On Tue, 5 Dec 2006 10:02:45 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>Steve
>
> Without sounding ignorant, do you mean:
>
> GetSQLValueString($_FILES['LOGO'],['Logo'],"text")
>
> rather than
>
> GetSQLValueString($HTTP_POST_VARS['LOGO'], "text")
>
> I couldn't find any exact reference to "$_POST['LOGO']" so am at a bit of a
>loss...
>

Sorry (forgot you were using an old version of PHP), you need to use:

GetSQLValueString($HTTP_FILES_VARS['LOGO']['name'], "text"),

instead of

GetSQLValueString($HTTP_POST_VARS['LOGO'], "text"),

--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 05, 2006 Dec 05, 2006
OK - tried that but it doesn't recognise FILES in the syntax - only Session (SESSION), cookie (COOKIE), post(POST) and URL(GET).

I've also tried FILE with no luck.
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 ,
Dec 05, 2006 Dec 05, 2006
On Tue, 5 Dec 2006 12:57:26 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>OK - tried that but it doesn't recognise FILES in the syntax - only Session (SESSION), cookie (COOKIE), post(POST) and URL(GET).
>
>I've also tried FILE with no luck.

What version of PHP are you using?
--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 05, 2006 Dec 05, 2006
5.2.0...


MySQL 5.0.27

or is it my version of dreamweaver that doesn't recognise it (i.e. go blue in code when recognised) I am using MX 6(.1update)
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 ,
Dec 05, 2006 Dec 05, 2006
On Tue, 5 Dec 2006 13:08:30 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>5.2.0...
>
>
>MySQL 5.0.27
>
>or is it my version of dreamweaver that doesn't recognise it (i.e. go blue in code when recognised) I am using MX 6(.1update)

When you make a page with:

<?php
phpinfo();
?>

and view it do you have register_long_arrays set to Off?

If so then $HTTP_POST_VARS won't work and you need to use $_POST
instead. Similarly with the other superglobal arays - which includes
$_FILES instead of $HTTP_FILES_VARS.

Off is the default so maybe this is your problem? Replace anything
like $HTTP_XXX_VARS with $_XXX.

I honestly can't remember back to MX 6.1 but it should recognize
$_FILES, $_POST etc.
--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 05, 2006 Dec 05, 2006
I wish it were that simple! - It is supporting about another 30 long arrays but interestingly, it liked the shorter version - i.e.

GetSQLValueString($_FILES['LOGO']['logo'], "text"),

However, when I run it, it still doesn't update the field - very annoying!!!!
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 ,
Dec 05, 2006 Dec 05, 2006
On Tue, 5 Dec 2006 15:52:35 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>I wish it were that simple! - It is supporting about another 30 long arrays but
>interestingly, it liked the shorter version - i.e.
>
> GetSQLValueString($_FILES['LOGO']['logo'], "text"),
>
> However, when I run it, it still doesn't update the field - very annoying!!!!

Whenever I get stuck like this I start with a simlple test page - a
dummy insert or update or whatever - and just add the form element
that is causing the headache. Why not try a simple form with a file
field and a submit button. Then look at the arrays when Submit is
pressed?

Try this test page:

<?php
if ( isset($_POST['Submit']) ) {
echo "<h1>POST array</h1>";
echo "<pre>";
print_r($_POST);
echo "</pre>";
echo "<h1>FILES array</h1>";
echo "<pre>";
print_r ($_FILES['LOGO']);
echo "</pre>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data"
name="form1">
<input type="file" name="LOGO" id="LOGO">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

When I test using a pdf on my hard drive I get this:

POST array
Array
(
[Submit] => Submit
)

FILES array
Array
(
[name] => COP2006B.pdf
[type] => application/pdf
[tmp_name] => C:\WINDOWS\TEMP\php401.tmp
[error] => 0
[size] => 71294
)

--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 05, 2006 Dec 05, 2006
Yay - cracked it - the sample code worked fine (as you would expect) so I checked the synatx and ammended the user error!

Many thanks for this Steve - a great help as usual
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
Engaged ,
Dec 05, 2006 Dec 05, 2006
Damn - spoke too soon.

It works fine now with just one logo but doesn't work with any others!

I have checked the logo filenames but still no luck.

Is this because it is remebering the $_Files array? If so, do I need a line to clear it before the new line goes in?
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 ,
Dec 05, 2006 Dec 05, 2006
On Tue, 5 Dec 2006 17:39:50 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>Damn - spoke too soon.
>
> It works fine now with just one logo but doesn't work with any others!
>
> I have checked the logo filenames but still no luck.
>
> Is this because it is remebering the $_Files array? If so, do I need a line
>to clear it before the new line goes in?

Any chance you could email me the whole page? It is hard to know
what's appening with just code snippets.
--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 06, 2006 Dec 06, 2006
Sent as requested....
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 ,
Dec 06, 2006 Dec 06, 2006
On Wed, 6 Dec 2006 09:37:25 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>Sent as requested....

Thanks. I just got in so I'll take a look after I've eaten! :-)
--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 06, 2006 Dec 06, 2006
hmmm.. haven't got anything yet - did you receive it?
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 ,
Dec 06, 2006 Dec 06, 2006
On Wed, 6 Dec 2006 14:39:20 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>hmmm.. haven't got anything yet - did you receive it?

Yeah, I'll get back to you as soon as I can...
--
Steve
steve at flyingtigerwebdesign dot 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 ,
Dec 06, 2006 Dec 06, 2006
On Wed, 6 Dec 2006 14:39:20 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>hmmm.. haven't got anything yet - did you receive it?

Well, I can't see anything obviously wrong except that I think you
should do a search and replace in code view - you need to search for
$HTTP_POST_VARS and replace with $_POST and also search for
$HTTP_SERVER_VARS and replace with $_SERVER

When you use this page (when it is on the server) is the record being
inserted into the database?

You say:

" It works fine now with just one logo but doesn't work with any
others!"

What do you mean? The first time you use the form (with say logo1.jpg)
it inserts the filename in the database but next time (with say
logo2.jpg) it still inserts logo1.jpg ?

Also, now I look again, there is no code to upload the logo to the
server! Did that get left out in the recent editing of the code?
--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 06, 2006 Dec 06, 2006
quote:

Originally posted by: Newsgroup User

Well, I can't see anything obviously wrong except that I think you
should do a search and replace in code view - you need to search for
$HTTP_POST_VARS and replace with $_POST and also search for
$HTTP_SERVER_VARS and replace with $_SERVER


Done - no change
quote:

Originally posted by: Newsgroup User
When you use this page (when it is on the server) is the record being
inserted into the database?


Yes - MySQL Database "DBCRM1" table "CONTACTS"
quote:

Originally posted by: Newsgroup User
You say:

" It works fine now with just one logo but doesn't work with any
others!"

What do you mean? The first time you use the form (with say logo1.jpg)
it inserts the filename in the database but next time (with say
logo2.jpg) it still inserts logo1.jpg ?


First time, it inserts the file path correctly and, if I select the same file path for a different record, it will attach it but if I select a different filename, it inserts a null value.
quote:

Originally posted by: Newsgroup User
Also, now I look again, there is no code to upload the logo to the
server! Did that get left out in the recent editing of the code?


eerrrmmm... didn't know you could do that! - all I was doing was physically putting all the logos into a logo directory on the server using windows explorer. Then I was trying to attach the file path onto the record... (just because its an intranet server)

It would be a hell of a lot easier to be able to upload the file to the correct directory.


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 ,
Dec 06, 2006 Dec 06, 2006
On Wed, 6 Dec 2006 16:05:12 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

> It would be a hell of a lot easier to be able to upload the file to the
>correct directory.

It's after midnight here so I'm going to call it a day. I'll have the
fixed file ready for you in the morning.

--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 06, 2006 Dec 06, 2006
OMG - didn't realise - sorry...
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 ,
Dec 06, 2006 Dec 06, 2006
On Wed, 6 Dec 2006 17:36:13 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

>OMG - didn't realise - sorry...

No worries.

I have done a demo for you. It mimics (as far as I can) your database
table and I have pre-loaded the form with test data to save a lot of
typing. Use it to upload logos (jpg or gif format) and then view the
inserted records (and logos using the link provided). I have zipped
the two files and my test database table for your perusal. Note that
the form is not validated - it is just for testing purposes and was
quickly done.

I have emailed the link and files to you.

HTH
--
Steve
steve at flyingtigerwebdesign dot 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
Engaged ,
Dec 07, 2006 Dec 07, 2006
At last - many many thanks

took a while to work out the differences but got there in the end.

Interestingly, the demo page you have works ok but comes up with the following error on submit.

While trying to retrieve the URL: http://www.flyingtiger-dev.com/uploaddemo/insertrecord.php?

The following error was encountered:

Read Error
The system returned:

(104) Connection reset by peerAn error condition occurred while reading data from the network. Please retry your request.

I can't thank you enough.
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 ,
Dec 07, 2006 Dec 07, 2006
LATEST
On Thu, 7 Dec 2006 09:42:24 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

> I can't thank you enough.

You're welcome!
--
Steve
steve at flyingtigerwebdesign dot 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