newbie newbie to php
am 01.09.2007 20:31:19 von Reggie
Am getting these messages.am trying to create an upload file for user
profile.something like myspace.please help.
Notice: Use of undefined constant completed - assumed 'completed' in /
home/fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php on line 17
Notice: Undefined index: completed in /home/fhlinux169/c/
clashoff.co.uk/user/htdocs/picture.php on line 17
Warning: fopen(../wellimg/ctco.jpg) [function.fopen]: failed to open
stream: No such file or directory in /home/fhlinux169/c/clashoff.co.uk/
user/htdocs/picture.php on line 46
Warning: filesize() [function.filesize]: stat failed for ../wellimg/
ctco.jpg in /home/fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php
on line 47
Warning: fread(): supplied argument is not a valid stream resource in /
home/fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php on line 47
Notice: Use of undefined constant gim - assumed 'gim' in /home/
fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php on line 52
Notice: Undefined index: gim in /home/fhlinux169/c/clashoff.co.uk/user/
htdocs/picture.php on line 52
This is the script:
// Connect to database
$errmsg = "";
if (! @mysql_connect("localhost","trainee","abc123")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("test");
// First run ONLY - need to create table by uncommenting this
// Or with silent @ we can let it fail every sunsequent time ;-)
$q = <<
create table pix (
pid int primary key not null auto_increment,
title text,
imgdata longblob)
CREATE;
@mysql_query($q);
// Insert any new image into database
if ($_REQUEST[completed] == 1) {
// Need to add - check for large upload. Otherwise the code
// will just duplicate old file ;-)
// ALSO - note that latest.img must be public write and in a
// live appliaction should be in another (safe!) directory.
move_uploaded_file($_FILES['imagefile']
['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")));
if (strlen($instr) < 149000) {
mysql_query ("insert into pix (title, imgdata) values
(\"".
$_REQUEST[whatsit].
"\", \"".
$image.
"\")");
} else {
$errmsg = "Too large!";
}
}
// Find out about latest image
$gotten = @mysql_query("select * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_assoc($gotten)) {
$title = htmlspecialchars($row[title]);
$bytes = $row[imgdata];
} else {
$errmsg = "There is no image in the database yet";
$title = "no database image available";
// Put up a picture of our training centre
$instr = fopen("../wellimg/ctco.jpg","rb");
$bytes = fread($instr,filesize("../wellimg/ctco.jpg"));
}
// If this is the image request, send out the image
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
?>
Upload an image to a database
Here's the latest picture
= $errmsg ?>

= $title ?>
Please upload a new picture and title
By Graham Ellis - graham@wellho.net
Re: newbie newbie to php
am 01.09.2007 21:10:04 von Jerry Stuckle
Reggie wrote:
> Am getting these messages.am trying to create an upload file for user
> profile.something like myspace.please help.
>
>
>
> Notice: Use of undefined constant completed - assumed 'completed' in /
> home/fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php on line 17
>
> Notice: Undefined index: completed in /home/fhlinux169/c/
> clashoff.co.uk/user/htdocs/picture.php on line 17
>
> Warning: fopen(../wellimg/ctco.jpg) [function.fopen]: failed to open
> stream: No such file or directory in /home/fhlinux169/c/clashoff.co.uk/
> user/htdocs/picture.php on line 46
>
> Warning: filesize() [function.filesize]: stat failed for ../wellimg/
> ctco.jpg in /home/fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php
> on line 47
>
> Warning: fread(): supplied argument is not a valid stream resource in /
> home/fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php on line 47
>
> Notice: Use of undefined constant gim - assumed 'gim' in /home/
> fhlinux169/c/clashoff.co.uk/user/htdocs/picture.php on line 52
>
> Notice: Undefined index: gim in /home/fhlinux169/c/clashoff.co.uk/user/
> htdocs/picture.php on line 52
>
>
> This is the script:
>
>
>
>
> // Connect to database
>
> $errmsg = "";
> if (! @mysql_connect("localhost","trainee","abc123")) {
> $errmsg = "Cannot connect to database";
> }
> @mysql_select_db("test");
>
> // First run ONLY - need to create table by uncommenting this
> // Or with silent @ we can let it fail every sunsequent time ;-)
>
> $q = <<
> create table pix (
> pid int primary key not null auto_increment,
> title text,
> imgdata longblob)
> CREATE;
> @mysql_query($q);
>
> // Insert any new image into database
>
> if ($_REQUEST[completed] == 1) {
> // Need to add - check for large upload. Otherwise the code
> // will just duplicate old file ;-)
> // ALSO - note that latest.img must be public write and in a
> // live appliaction should be in another (safe!) directory.
> move_uploaded_file($_FILES['imagefile']
> ['tmp_name'],"latest.img");
> $instr = fopen("latest.img","rb");
> $image = addslashes(fread($instr,filesize("latest.img")));
> if (strlen($instr) < 149000) {
> mysql_query ("insert into pix (title, imgdata) values
> (\"".
> $_REQUEST[whatsit].
> "\", \"".
> $image.
> "\")");
> } else {
> $errmsg = "Too large!";
> }
> }
>
> // Find out about latest image
>
> $gotten = @mysql_query("select * from pix order by pid desc limit 1");
> if ($row = @mysql_fetch_assoc($gotten)) {
> $title = htmlspecialchars($row[title]);
> $bytes = $row[imgdata];
> } else {
> $errmsg = "There is no image in the database yet";
> $title = "no database image available";
> // Put up a picture of our training centre
> $instr = fopen("../wellimg/ctco.jpg","rb");
> $bytes = fread($instr,filesize("../wellimg/ctco.jpg"));
> }
>
> // If this is the image request, send out the image
>
> if ($_REQUEST[gim] == 1) {
> header("Content-type: image/jpeg");
> print $bytes;
> exit ();
> }
> ?>
>
>
> Upload an image to a database
> Here's the latest picture
> = $errmsg ?>
> 
> = $title ?>
>
> Please upload a new picture and title
>
>
> By Graham Ellis - graham@wellho.net
>
>
>
Strings need to be enclosed by '' or "".
if ($_REQUEST['completed'] == 1) {
...
And your fopen() is failing because the file doesn't exist (at least
where you said it is).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: newbie newbie to php
am 01.09.2007 21:17:00 von ELINTPimp
> // First run ONLY - need to create table by uncommenting this
> // Or with silent @ we can let it fail every sunsequent time ;-)
>
> $q = <<
> create table pix (
> pid int primary key not null auto_increment,
> title text,
> imgdata longblob)
> CREATE;
> @mysql_query($q);
>
This makes babies cry.
Re: newbie newbie to php
am 01.09.2007 23:28:13 von unknown
Post removed (X-No-Archive: yes)
Re: newbie newbie to php
am 01.09.2007 23:28:52 von unknown
Post removed (X-No-Archive: yes)
Re: newbie newbie to php
am 03.09.2007 11:15:56 von Erwin Moller
ELINTPimp wrote:
>> // First run ONLY - need to create table by uncommenting this
>> // Or with silent @ we can let it fail every sunsequent time ;-)
>>
>> $q = <<
>> create table pix (
>> pid int primary key not null auto_increment,
>> title text,
>> imgdata longblob)
>> CREATE;
>> @mysql_query($q);
>>
>
> This makes babies cry.
Not only babies.
I am a big boy, also crying over this approach.
Advise to the OP: NEVER EVER use code again from that 'programmer'.
Regards,
Erwin Moller
Re: newbie newbie to php
am 04.09.2007 08:02:42 von laptopia
On Sep 3, 4:15 am, Erwin Moller
wrote:
> ELINTPimp wrote:
> >> // First run ONLY - need to create table by uncommenting this
> >> // Or with silent @ we can let it fail every sunsequent time ;-)
>
> >> $q = <<
> >> create table pix (
> >> pid int primary key not null auto_increment,
> >> title text,
> >> imgdata longblob)
> >> CREATE;
> >> @mysql_query($q);
>
> > This makes babies cry.
Can someone give an example of why this is bad programming practice?
Is it because he is storing the image in the database?
it
Re: newbie newbie to php
am 04.09.2007 09:05:16 von luiheidsgoeroe
On Tue, 04 Sep 2007 08:02:42 +0200, stiki wrote:
> On Sep 3, 4:15 am, Erwin Moller
> wrote:=
>> ELINTPimp wrote:
>> >> // First run ONLY - need to create table by uncommenting this
>> >> // Or with silent @ we can let it fail every sunsequent time ;-)
>>
>> >> $q =3D <<
>> >> create table pix (
>> >> pid int primary key not null auto_increment,
>> >> title text,
>> >> imgdata longblob)
>> >> CREATE;
>> >> @mysql_query($q);
>>
>> > This makes babies cry.
>
>
> Can someone give an example of why this is bad programming practice?
> Is it because he is storing the image in the database?
It's the @, and continuing on with a query one knows for sure to create =
an =
(sql) error again and again and again after the first time. Never =
appropriate.
-- =
Rik Wasmus
Re: newbie newbie to php
am 04.09.2007 13:27:26 von Courtney
Rik Wasmus wrote:
> On Tue, 04 Sep 2007 08:02:42 +0200, stiki wrote:
>
>> On Sep 3, 4:15 am, Erwin Moller
>> wrote:
>>> ELINTPimp wrote:
>>> >> // First run ONLY - need to create table by uncommenting this
>>> >> // Or with silent @ we can let it fail every sunsequent time ;-)
>>>
>>> >> $q = <<
>>> >> create table pix (
>>> >> pid int primary key not null auto_increment,
>>> >> title text,
>>> >> imgdata longblob)
>>> >> CREATE;
>>> >> @mysql_query($q);
>>>
>>> > This makes babies cry.
>>
>>
>> Can someone give an example of why this is bad programming practice?
>> Is it because he is storing the image in the database?
>
>
> It's the @, and continuing on with a query one knows for sure to create
> an (sql) error again and again and again after the first time. Never
> appropriate.
well why?
I mean if you want to set for the existence of the table pseudo code
wise :-
if (table doesn't exist)
create table;
seems to me about as functionally simmilar as
try to create table, and ignore errors that it exists;
In one case the checking is explicit at the coding level, at the other
it is implicit with the mysql library. I doubt that the actual CPU
cycles differ much, and yu could argue this only requires ONE call to
the Mysql library functions, not two.
It seems to me an issue of pure style. And whether the person coming
along next says 'cunning!' or 'stupid!'
Re: newbie newbie to php
am 04.09.2007 13:43:06 von Jerry Stuckle
The Natural Philosopher wrote:
> Rik Wasmus wrote:
>> On Tue, 04 Sep 2007 08:02:42 +0200, stiki wrote:
>>
>>> On Sep 3, 4:15 am, Erwin Moller
>>> wrote:
>>>> ELINTPimp wrote:
>>>> >> // First run ONLY - need to create table by uncommenting this
>>>> >> // Or with silent @ we can let it fail every sunsequent time ;-)
>>>>
>>>> >> $q = <<
>>>> >> create table pix (
>>>> >> pid int primary key not null auto_increment,
>>>> >> title text,
>>>> >> imgdata longblob)
>>>> >> CREATE;
>>>> >> @mysql_query($q);
>>>>
>>>> > This makes babies cry.
>>>
>>>
>>> Can someone give an example of why this is bad programming practice?
>>> Is it because he is storing the image in the database?
>>
>>
>> It's the @, and continuing on with a query one knows for sure to
>> create an (sql) error again and again and again after the first time.
>> Never appropriate.
>
>
> well why?
>
> I mean if you want to set for the existence of the table pseudo code
> wise :-
>
> if (table doesn't exist)
> create table;
>
> seems to me about as functionally simmilar as
>
> try to create table, and ignore errors that it exists;
>
> In one case the checking is explicit at the coding level, at the other
> it is implicit with the mysql library. I doubt that the actual CPU
> cycles differ much, and yu could argue this only requires ONE call to
> the Mysql library functions, not two.
>
> It seems to me an issue of pure style. And whether the person coming
> along next says 'cunning!' or 'stupid!'
You shouldn't be creating a table if it already exists...
If you need tables, they should be created on installation. You
generally shouldn't have to create or drop tables while your program is
running. If you are, chances are you've got a design problem.
And if this is during installation, you should go ahead and show the
messages so the user knows what happened. That way if they call you
with other problems (i.e. the table structure is incorrect because it's
a duplicate table name), you have someplace to start.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================