Re: image uploads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, January 31, 2006 10:58 am, William Stokes wrote:
> Is there something special about php and images that nobody told me...

No. :-)

> I'm writing a image gallery but I have  run to serious trouble with
> it. I
> have one page with form in it. Form's action is $PHP_SELF. In the form
> there
> is just one file field called "image".

Add the ENCTYPE="multipart/form-data" to the FORM tag, if you don't
have it.

> I test if there's users image to handle with
> if (isset($img))

You mean isset($image), right?...
The name above is "image"...

Post source code snippets.

> if there's one. I greate two new images using
>
> imagecreatefromjpeg()
> imagecreatetruecolor()
> imagecopyresampled()
>
> in two different functions. At the end of both functions there's
> imagedestroy($img). After that the both image information is stored to
> DB

Storing the image in the DB is probably not a Good Idea for a variety
of reasons.

There is a highly-optimized much more mature specialized database
specifically designed for large-file operations (LFO)...

It's called "the file system" :-)

> and, if succeful, at the end I do unset($img) to clear the old image
> variable from memory. Both new images are created OK and DB update
> works OK.

OK...

> But nothing else doesn't work.

You'd have to give us a lot more than "doesn't work"...

We've got nothing to work on here.

> I don't know what I have to do to
> prevent the
> image from realoading to server second time if user hits browser
> refresh
> button. The same image is uploaded every time the user hits refresh.

Well, yeah, if they upload the same image again, then you're going to
get it again.

If you don't want to allow that, then include a unique token
http://php.net/uniqid in the form you send them, and when they upload
the first image, mark that token as "used" and don't let them do it
again.

You could also do a binary-safe string comparison of the new image
with the images already in the database -- That would be slower, but
would dis-allow somebody from filling out the form again with a new
token and uploading the same image a second time.

> Another
> thing is that Opera stopped co-operation with this page once and for
> all. It
> just freezes after the page call's itself. IE and Firefox doesn't.

Opera freezing up is probably a separate problem entirely.  Ignore it
until you get the application working the way you want it to work.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux