php-general Digest 31 Oct 2010 02:05:53 -0000 Issue 7013
Topics (messages 309149 through 309156):
a loop constructing the URLs and make PHP to fetch up to 100 pages [ a seven
liner]
309149 by: jobst_m=C3=BCller
Re: Watermark with GD
309150 by: Gary
309151 by: Gary
309152 by: tedd
309153 by: Gary
309154 by: Ashley Sheridan
309155 by: Tamara Temple
questions about if statements regarding a checkbox
309156 by: Ben Brentlinger
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
dear list - good Morning!
i want to parse the site - and get the results out of it:
http://www.educa.ch/dyn/79363.asp?action=search
therefore i need to loop over the line 2 - don ´ i!?
<?php
$data = file_get_contents('http://www.educa.ch/dyn/79363.asp?action=search');
$regex = '/Page 1 of (.+?) results/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>
in order to get the details of the pages -
http://www.educa.ch/dyn/79376.asp?id=4438
http://www.educa.ch/dyn/79376.asp?id=53
and so forth - well i need a foreach statement in line two - don´ t i!?
just help me with this seven-liner ;)
on a sidenote: measuring code in terms of how many lines it took to write is
a Perl-coder-attitude. Only Perl programmers care about that and i find it hard
it is to read Perl code.
love to hear from you
___________________________________________________________
GRATIS! Movie-FLAT mit über 300 Videos.
Jetzt freischalten unter http://movieflat.web.de
--- End Message ---
--- Begin Message ---
"tedd" <[email protected]> wrote in message
news:p06240800c8f1d19b9...@[192.168.1.2]...
> At 3:05 PM -0400 10/29/10, Gary wrote:
>>I am trying to get the watermark to work, however I am having a problem in
>>that the image is being called from a database (image sits in images
>>file).
>>
>>The script in question is this
>>
>>$image = imagecreatefromjpeg($_GET['src']);
>>
>>However it produces an error message of
>>
>>Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename
>>cannot be empty in /home/content/a/l/i/alinde52/html/imagesDetail.php on
>>line 233
>>
>>I have tried various methods, for example: ($_GET ['images/'] or ($_GET
>>['images/$row_WADAimages["image_id"]].
>>
>>Can anyone shed some light on this for me.
>>
>>Thank you
>>
>>Gary
>
> Gary:
>
> Several things.
>
> 1. Getting an image from a database? You mean that you are getting the
> path of the image in the file system, right?
>
> Side note: You could place the image inside the database using a BLOB and
> do away with the path all together. That has the benefit of being
> portable -- you simply move the database to where ever you want it. The
> downside is that the database becomes very large, but no more so that the
> file system. There are pro's and con's in storing actual images in a
> database.
>
> 2. Using a GET is not the way to get the path. Instead, you have to
> retrieve the path from the database table where the path is stored --
> and that requires a MySQL query similar to "SELECT * FROM <database> WHERE
> id=<whatever>". There are lot's of examples of how to pull data from a
> database.
>
> 3. After getting the path, then you can create the watermark like so:
>
> http://webbytedd.com/b/watermark/
>
> Hope this helps,
>
> tedd
>
> --
> -------
> http://sperling.com/
>
tedd
Thank you for your reply.
I was under the impression that the image is stored in a folder called
images, in fact the images file do go in, however I have the DB set up for
longblob, averaging about 20kb each, so now I am unsure. I exported the sql
so perhaps you can tell me.
Table structure for table `images`
--
CREATE TABLE IF NOT EXISTS `images` (
`image_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`caption` varchar(50) NOT NULL,
`wheretaken` varchar(100) NOT NULL,
`description` text NOT NULL,
`file_name` varchar(25) NOT NULL,
`image_file` longblob NOT NULL,
`submitted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`image_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1447 ;
When I call the images, which works fine, I do need to specify the path that
leads to the images folder. Am I being redundant in this structure.
This is the script that I use to call the images. I have pulled out some of
the html that styles the data.
<?php if ($totalRows_WADAimages > 0) { // Show if recordset not empty ?>
<?php echo $row_WADAimages["caption"]; ?>
src="images/<?php echo $row_WADAimages["image_file"]; ?>" <?php echo
$row_WADAimages["description"]; ?>"
<?php echo $row_WADAimages["where_taken"]; ?>
<?php echo $row_WADAimages["description"]; ?>
Thank you for your help.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5576 (20101029) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
"Tamara Temple" <[email protected]> wrote in message
news:[email protected]...
> On Oct 29, 2010, at 2:44 PM, Gary wrote:
>> "Adam Richardson" <[email protected]> wrote in message
>> news:[email protected]...
>> On Fri, Oct 29, 2010 at 3:05 PM, Gary <[email protected]> wrote:
>>> I am trying to get the watermark to work, however I am having a problem
>>> in
>>> that the image is being called from a database (image sits in images
>>> file).
>>>
>>> The script in question is this
>>>
>>> $image = imagecreatefromjpeg($_GET['src']);
>>>
>>> However it produces an error message of
>>>
>>> Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename
>>> cannot be empty in /home/content/a/l/i/alinde52/html/ imagesDetail.php
>>> on
>>> line 233
>>>
>>
>> First things first. It looks like there's nothing in $_GET['src'].
>> From where are you getting the value 'src'?
>>
>> Adam
>>
>> **
>> Adam
>>
>> Thanks for your reply, that is my question, what is to replace ['src']
>> if I
>> am calling the image from a database.
>>
>> Gary
>
> I'd really need to know more about this application to help. If you are
> calling the image from a database (does this mean you have the image's
> file spec saved in the database, or you actually storing the image data
> in the database?), you need to use a query to do that. Is the
> imagesDetail.php script being called by something else that already
> queried the database and put the file spec in the src query string
> argument? Before you dump the query string argument directly into the
> imagecreatefromjpeg() funciton, you should verify that it exists:
>
> if (isset($_GET['src'[) && (!empty($_GET['src'[) {
> $src = $_GET['src'];
> if (fileexists($src)) {
> $image = imageceatefromjpeg($src);
> if ($image === FALSE) {
> # process error from imagecreatefromjpeg
> }
> } else {
> # process missing image
> }
> } else {
> # process missing query string parameter
> }
>
> This is all prediated on the idea that something is calling your
> imageDetail.php script with the source path for the image in question. If
> that is not the case, and you need to in fact query the database for the
> source path of the image, then you need to do a database query.
>
> Not knowing anything about how your database is set up, I'll take a stab
> at a generic method of doing it.
>
> Somehow, imageDetail.php needs to know what image to get. Let's assume
> you are calling it from a gallery that has several images displayed. Part
> of the information needed is some what to identify the image's record in
> the database. Let's assume you have images stored with an id, that is not
> null and autoincrements when you store a new image. Here's a sample
> schema:
>
> CREATE TABLE `photos` (
> `id` INT AUTO_INCREMENT NOT NULL,
> `src` VARCHAR(255) NOT NULL,
> `created` TIMESTAMP NOT NULL DEFAULT 0,
> `updated` TIMESTAMP NOT NULL DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP
> PRIMARY KEY (`id`)
> );
>
> Of course, you would probably want to store a lot more info about an
> image, but this will do for explanation.
>
> Let's say you have a gallery shown at your application's index.php
> program. In the html it generates, you may have something like this for
> any particular thumbnail:
>
>
> <a href="imageDetail.php?id=25"><img src="thumbs/imageABC.jpg"></a>
>
> This is making some assumptions:
> * you have image thumbnails for each image stored in the subdirectory
> thumbs/
> * you've figured out somehow that the id for thumbs/imageABC.jpg is 25
>
> When the user clicks on the image, they get taken to your imageDetail.php
> script, with the query string paramter id set to 25.
>
> In PHP you would then do:
>
> if (isset($_GET['id'] && (!empty($_GET['id'] && is_numeric($_GET['id']) {
> $id = $_GET['id'];
> $sql = "SELECT * FROM `photos` WHERE id=".$id." LIMIT 1";
> $result = mysql_query($sql,$db);
> if ($result) {
> $imagedata = mysql_fetch_array($result,MYSQL_ASSOC);
> $src = $imagedata['src'];
> if (isset($src) && !empty($src) && fileexists($src)) {
> $image = imagecreatefromjpeg($src);
>
> # do stuff with image
>
> } else {
>
> # handle invalid src data
>
> }
> } else {
>
> # handle error from query
>
> }
> } else {
>
> # handle invalid id paramter on script
>
> }
>
>
> Note: some people like to handle error conditions before moving on to
> working with the successful state. It's a matter of style. Either works.
>
> Hope this helps.
>
> Tamara
>
Tamara
Thanks for your reply. The image is already called, (and if you read the
response I posted to tedd, you'll see I am now not sure how it is). I also
posted the code that calls the image if that sheds any light.
I am digesting all the information to get it to work, if any of the code
changes your answer, I would love to hear it!
Thank you again.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5576 (20101029) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
At 10:31 AM -0400 10/30/10, Gary wrote:
I was under the impression that the image is stored in a folder called
images, in fact the images file do go in, however I have the DB set up for
longblob, averaging about 20kb each, so now I am unsure. I exported the sql
so perhaps you can tell me.
Gary:
Impressions don't cut it -- you should *know* if the actual images
are in the file system or in the database. Find that out before we
can proceed.
Cheers,
tedd
--
-------
http://sperling.com/
--- End Message ---
--- Begin Message ---
"tedd" <[email protected]> wrote in message
news:p06240804c8f1eaf38...@[192.168.1.2]...
> At 10:31 AM -0400 10/30/10, Gary wrote:
>>
>>I was under the impression that the image is stored in a folder called
>>images, in fact the images file do go in, however I have the DB set up for
>>longblob, averaging about 20kb each, so now I am unsure. I exported the
>>sql
>>so perhaps you can tell me.
>
> Gary:
>
> Impressions don't cut it -- you should *know* if the actual images are in
> the file system or in the database. Find that out before we can proceed.
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com/
tedd
The images do go into the images folder, what I am now unclear about is
where they are being called from.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5576 (20101029) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
On Sat, 2010-10-30 at 11:50 -0400, Gary wrote:
> "tedd" <[email protected]> wrote in message
> news:p06240804c8f1eaf38...@[192.168.1.2]...
> > At 10:31 AM -0400 10/30/10, Gary wrote:
> >>
> >>I was under the impression that the image is stored in a folder called
> >>images, in fact the images file do go in, however I have the DB set up for
> >>longblob, averaging about 20kb each, so now I am unsure. I exported the
> >>sql
> >>so perhaps you can tell me.
> >
> > Gary:
> >
> > Impressions don't cut it -- you should *know* if the actual images are in
> > the file system or in the database. Find that out before we can proceed.
> >
> > Cheers,
> >
> > tedd
> >
> >
> > --
> > -------
> > http://sperling.com/
>
> tedd
>
> The images do go into the images folder, what I am now unclear about is
> where they are being called from.
>
> Gary
>
>
>
> __________ Information from ESET Smart Security, version of virus signature
> database 5576 (20101029) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
OK, what it looks like is that the path to your image file is being
stored in the database, and you're outputting that path inside of an
<img> tag when you output the HTML. That's fine, and is the method I use
all the time.
Now, back to the original question. You want to overlay some text on it
as a watermark? For that, you need to use the GD functions.
First, use GD to load in the image. Note that the path you use to open
the image here won't be the same as the one you have in the DB. That's
because the one in the DB is the path that is available to web browsers
to reference your image, which is uses relative to your web page. For
example, if your page was at
http://www.someplace.com/somefolder/page/php, and the image tag looked
like <img src="images/image.jpg"/> the browser path to the images would
be http://www.someplace.com/somefolder/image.jpg , but the script path
to your image would be very different, such as one of the following:
* c:\xampp\htdocs\websitename\somefolder\images\image.jpg (xampp
on windows)
* /var/www/html/websitename/somefolder/images/image.jpg (linux)
* /srv/www/websitename/somefolder/images/image.jpg (linux)
* /home/websitename/somefolder/images/image.jpg (linux)
Those are only examples, and may not necessarily be the exact setup you
have on your server, you should find out exactly what the server is
running. You can also reference it via a relative path, which is
relative to the PHP script.
With GD, you can either save a duplicate of the image with the watermark
on, with a useful name such as watermark_image.jpg, or you can output it
directly with the proper headers. If you do choose the latter route, you
should ideally make a separate image script for making the watermark
image, and in your image tag, call it with something like:
<img src="image.php?image_id=id"/>
The id can be whatever id you've got for the image in your database, and
then in your image.php script, make the DB call that grabs the
information for that image, and create the watermark. Just remember to
make sure you send the right headers or your image won't show!
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Oct 30, 2010, at 9:31 AM, Gary wrote:
"tedd" <[email protected]> wrote in message
news:p06240800c8f1d19b9...@[192.168.1.2]...
At 3:05 PM -0400 10/29/10, Gary wrote:
I am trying to get the watermark to work, however I am having a
problem in
that the image is being called from a database (image sits in images
file).
The script in question is this
$image = imagecreatefromjpeg($_GET['src']);
However it produces an error message of
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]:
Filename
cannot be empty in /home/content/a/l/i/alinde52/html/
imagesDetail.php on
line 233
I have tried various methods, for example: ($_GET ['images/'] or
($_GET
['images/$row_WADAimages["image_id"]].
Can anyone shed some light on this for me.
Thank you
Gary
Gary:
Several things.
1. Getting an image from a database? You mean that you are getting
the
path of the image in the file system, right?
Side note: You could place the image inside the database using a
BLOB and
do away with the path all together. That has the benefit of being
portable -- you simply move the database to where ever you want it.
The
downside is that the database becomes very large, but no more so
that the
file system. There are pro's and con's in storing actual images in a
database.
2. Using a GET is not the way to get the path. Instead, you have to
retrieve the path from the database table where the path is stored --
and that requires a MySQL query similar to "SELECT * FROM
<database> WHERE
id=<whatever>". There are lot's of examples of how to pull data
from a
database.
3. After getting the path, then you can create the watermark like so:
http://webbytedd.com/b/watermark/
Hope this helps,
tedd
--
-------
http://sperling.com/
tedd
Thank you for your reply.
I was under the impression that the image is stored in a folder called
images, in fact the images file do go in, however I have the DB set
up for
longblob, averaging about 20kb each, so now I am unsure. I exported
the sql
so perhaps you can tell me.
Table structure for table `images`
--
CREATE TABLE IF NOT EXISTS `images` (
`image_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`caption` varchar(50) NOT NULL,
`wheretaken` varchar(100) NOT NULL,
`description` text NOT NULL,
`file_name` varchar(25) NOT NULL,
`image_file` longblob NOT NULL,
`submitted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`image_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1447 ;
When I call the images, which works fine, I do need to specify the
path that
leads to the images folder. Am I being redundant in this structure.
This is the script that I use to call the images. I have pulled out
some of
the html that styles the data.
<?php if ($totalRows_WADAimages > 0) { // Show if recordset not
empty ?>
<?php echo $row_WADAimages["caption"]; ?>
src="images/<?php echo $row_WADAimages["image_file"]; ?>" <?php echo
$row_WADAimages["description"]; ?>"
<?php echo $row_WADAimages["where_taken"]; ?>
<?php echo $row_WADAimages["description"]; ?>
Thank you for your help.
Gary
is this the imageDetail.php script?
From what it appears in the code, `image_file` is holding the file
name rather than the actual image. Yet you have `image_file` defined
as a longblob, which would make sense if you were storing the actual
image data in the data base rather than on the file system. As Ashley
noted, you can do it either way. I notice you also have a field
`file_name` -- what is this used for? It sounds like your design is a
bit off -- neither one way or the other. The php shown doesn't look
complete enough, though -- where is the img tag and such? Also, going
in and out of php on each line is kind of a waste and looks sloppy. If
i read that code right, it would emit something like this:
caption text
src="images/pathtoimagefile" description text
where taken text
description text
Look at the html that's emitted from the script and see if that's what
you get.
Can you post or pastebin more of the .php script so I can see more of
what is going on?
--- End Message ---
--- Begin Message ---
hello,
I'd like to know the proper code to use in a php script that processes a
form with a checkbox in order to send one email if the checkbox has been
checked and another email if the checkbox hasn't. I tried if($check ==
true) and I tried putting the word "true" in double quotes, and both of
them caused the "unexpected variable" syntax error. The only problem
is, all I could think to use was that line of code I just used, I'm not
sure what the proper syntax is for checkbox when using the if statement
to send one email when the checkbox is checked and a different email
when it's not checked. I'm wanting to send an email to the site admin
with the information given by the person who filled out the form that
contains the checkbox.
Thanks,
Ben
--- End Message ---