Skip to main content
Inspiring
December 4, 2006
Answered

Uploading/ Inserting image file URL

  • December 4, 2006
  • 23 replies
  • 1095 views
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"),
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Newsgroup_User
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

23 replies

Inspiring
December 5, 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?
Inspiring
December 5, 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
Inspiring
December 5, 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
Inspiring
December 5, 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!!!!
Inspiring
December 5, 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
Inspiring
December 5, 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)
Inspiring
December 5, 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
Inspiring
December 5, 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.
Inspiring
December 5, 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
Inspiring
December 5, 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...