freelanceprogrammers.org Forum Index » PHP

File uploading?


View user's profile Post To page top
gryphon4200 Posted: Fri Apr 29, 2005 8:29 pm


Joined: 23 Apr 2005

Posts: 10
File uploading?
I`m trying to figure out how to upload an image into a MySQL database.
For some reason everything is working except the filedata.

This is what I have so far:

Database setup:
Database - test
Table - data(filename text not null, description text not null, filedata
longblob not null)

FileUpload.html:

<html>
<head><title>File Upload Test</title></head>
<body>

<form method=`post` enctype=`multipart/form-data` action=`InsertData.php`>
<p>Filename:<br>
<input type=`text` name=`filename` size=`40`>
</p>
<p>FileData:<br>
<input type=`file` name=`filedata` size=`40` accept=`image/jpeg`>
</p>
<p>Description:<br>
<textarea name=`description` rows=`3` cols=`40`></textarea>
<input type=`submit` value=`Send`>
</p>
</form>

</body>
</html>

InsertData.php:

<?php

$FileName=$_POST[`filename`];
$Description=$_POST[`description`];
$FileData=$_POST[`filedata`];

$Host = "127.0.0.1";
$Username = "root";
$Password = "";

$link = @mysql_connect($Host, $Username, $Password) or die ("Unable to connect
to server");

echo "Link established<br>";

mysql_select_db("test", $link) or die ("Unable to select database");

echo "Database selected<br>";

mysql_query("insert into data(filename, description, filedata) values
(`$FileName`, `$Description`, `$FileData`)");

echo "Ran Query<br>";

mysql_close($link);

echo "Link Closed<br>";
?>

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
delvtecsol Posted: Fri Apr 29, 2005 8:36 pm


Joined: 29 Apr 2005

Posts: 10
File uploading?
Gryphon wrote:
> I`m trying to figure out how to upload an image into a MySQL database.
> For some reason everything is working except the filedata.


may i ask why you are placing an image into a database?

yes, it can be done, but the file system is SOOOO much better at
handling FILES than mysql could ever dream to be.
Reply with quote
Send private message
View user's profile Post To page top
gryphon4200 Posted: Fri Apr 29, 2005 8:39 pm


Joined: 23 Apr 2005

Posts: 10
File uploading?
I thought it would make things easier in the long run. I guess the best thing
for me to do would be to upload the file to the server and then refrence the
location in the database. But either way I`m still having problems uploading
anything. I know I`m just missing something simple but I`m at a loss..



ICQ UIN# 1899918
Yahoo ID: Gryphon4200
AIM Name: Gryphon4200
MSN Name: Gryphon4200

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
paul_hodel Posted: Fri Apr 29, 2005 8:45 pm


Joined: 29 Apr 2005

Posts: 4
File uploading?
Hey,

Do this...

mysql_query("insert into data(filename, description) values (`$filedata_name`,
`$description`)");

copy($filedata, `/path/$filedata_name`);

Paul Hodel
Gerente de Tecnologia (paul@...)

9618-8904 / 326-6267
----- Original Message -----
From: Gryphon
To: php-objects@yahoogroups.com
Sent: Friday, April 29, 2005 12:29 PM
Subject: [php-objects] File uploading?


I`m trying to figure out how to upload an image into a MySQL database.
For some reason everything is working except the filedata.

This is what I have so far:

Database setup:
Database - test
Table - data(filename text not null, description text not null, filedata
longblob not null)

FileUpload.html:

<html>
<head><title>File Upload Test</title></head>
<body>

<form method=`post` enctype=`multipart/form-data` action=`InsertData.php`>
<p>Filename:<br>
<input type=`text` name=`filename` size=`40`>
</p>
<p>FileData:<br>
<input type=`file` name=`filedata` size=`40` accept=`image/jpeg`>
</p>
<p>Description:<br>
<textarea name=`description` rows=`3` cols=`40`></textarea>
<input type=`submit` value=`Send`>
</p>
</form>

</body>
</html>

InsertData.php:

<?php

$FileName=$_POST[`filename`];
$Description=$_POST[`description`];
$FileData=$_POST[`filedata`];

$Host = "127.0.0.1";
$Username = "root";
$Password = "";

$link = @mysql_connect($Host, $Username, $Password) or die ("Unable to connect
to server");

echo "Link established<br>";

mysql_select_db("test", $link) or die ("Unable to select database");

echo "Database selected<br>";

mysql_query("insert into data(filename, description, filedata) values
(`$FileName`, `$Description`, `$FileData`)");

echo "Ran Query<br>";

mysql_close($link);

echo "Link Closed<br>";
?>

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


PHP Data object relational mapping generator - http://www.meta-language.net/



------------------------------------------------------------------------------
Yahoo! Groups Links

a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/php-objects/

b.. To unsubscribe from this group, send an email to:
php-objects-unsubscribe@yahoogroups.com

c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.




------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.3 - Release Date: 25/4/2005


[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
lucius_decrius Posted: Mon May 02, 2005 5:58 pm


Joined: 02 May 2005

Posts: 7
File uploading?
Hello all,
I`m having some problem with connection to MS-SQL on PHP.
We have this application that we stopped developping about an year ago,
and now we got back at it.
By that time we already had this problem, I`m testing the application
and suddenly I cannot connect to DB anymore.
We use a database abstraction layer to connect to Oracle and Firebird
also, and this problem does not happen with either of them.
The only possible reason I could think about was the pconnect function.
I`m clueless here.
Any tips?
Thanks in advance.

Eduardo Sampaio
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help