Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in PHP only
Search
Advanced Search
Forums
BYTES
Product Launch
Updates
Developer Toolkit
Today's Posts
Member List
Calendar
Home
Forum
Topic
PHP
how can image be uploaded
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
anuragpj
New Member
Join Date:
Jan 2007
Posts:
32
#1
how can image be uploaded
Mar 9 '07, 10:33 AM
I want that a user can upload his image .
How can his image be stored in the database and can be retrieved from database?
millertime90
New Member
Join Date:
Feb 2007
Posts:
3
#2
Mar 9 '07, 09:44 PM
Originally posted by
anuragpj
I want that a user can upload his image .
How can his image be stored in the database and can be retrieved from database?
check out post
http://www.thescripts.com/forum/thread614464.html
should have the solution your looking for.
Comment
Post
Cancel
ronverdonk
Recognized Expert
Specialist
Join Date:
Jul 2006
Posts:
4259
#3
Mar 9 '07, 09:55 PM
Look at this reply to a similar question I just posted
http://www.thescripts.com/forum/post2424480-4.html
Ronald :cool:
Comment
Post
Cancel
DavidPr
New Member
Join Date:
Mar 2007
Posts:
155
#4
Mar 18 '07, 03:49 AM
I read that thread and downloaded the zip files. The script works great, but how do I display the pictures?
Comment
Post
Cancel
anandaraman
New Member
Join Date:
Feb 2007
Posts:
8
#5
Mar 20 '07, 10:45 AM
Main.php
<title> File Upload and Download (MYSQL Database)</title>
<h2 align="center"> File Upload and Download (MYSQL Database)</h2>
<table width="200" border="0" align="center" >
<tr id="trr">
<td align="center"> <a href="upload.ph p?up=yes"><stro ng>
Upload File
</strong> </a> </td>
</tr>
<tr id="trr" >
<td align="center"> <a href="download. php?dw=yes"><st rong>
Download File
</strong> </a></td>
</tr>
</table>
upload.php
<title>Upload Files to MYSQL Database</title>
<h2 align="center"> Upload Files to MYSQL Database</h2>
<?php
if($_GET['up']=="yes")
{
print '<form name="uplform" action="" method="post" enctype="multip art/form-data" >
<table width="450" border="0" align="center" ><stron>
<tr id="trr">
<th width="207">Fil e Upload </th>
<td width="233"><in put type="file" name="uplfile" value="sss"></td></tr>
<tr id="trr">
<td> </td>
<td> </td>
</tr>
<tr id="trr">
<td align="right">< input type="submit" name="Submit" value="Submit"> </td>
<td><input type="reset" name="Reset" value="Reset"></td>
</tr></strong>
</table></form>';
}
?>
<?php
if(isset($_POST['Submit']) && $_POST['Submit']=="Submit")
{
$flag=0;
if(isset($HTTP_ POST_FILES['uplfile']))
{
if(is_uploaded_ file($HTTP_POST _FILES['uplfile']['tmp_name']))
if(!file_exists ($HTTP_POST_FIL ES['uplfile']['name']))
if(@rename($HTT P_POST_FILES['uplfile']['tmp_name'],$HTTP_POST_FIL ES['uplfile']['name']))
$flag=1;
else
$flag=0;
}
if($flag==1)
{
$file_u=$HTTP_P OST_FILES['uplfile']['name'];
$da=date("Y-m-d ",time() + (34200)).date(" H:i:s",time() + (34200));
mysql_connect(" localhost","roo t","") or die("Sever connection error");
mysql_select_db ("file") or die ("Database error");
$val = fread(fopen($fi le_u, "r+"), filesize($file_ u)+1);
if (!empty($val))
{
$val = '0x' . bin2hex($val);
$ext=substr($HT TP_POST_FILES['uplfile']['name'],strlen($HTTP_P OST_FILES['uplfile']['name'])-3,3);
$q1="INSERT INTO `file_tb` ( `id` , `file_name` , `file` , `ext` , `date_time` )
VALUES ( NULL , '$file_u', $val, '$ext', '$da')";
if(@mysql_query ($q1))
print '<h1 align="center"> File Successfully Uploaded</h1>';
else
print '<h1 align="center"> File is too Large</h1>';
}
$do=unlink ($HTTP_POST_FIL ES['uplfile']['name']);
}
}
?>
download.php
<title>Downlo ad Files From MYSQL Database</title>
<h2 align="center"> Download Files From MYSQL Database</h2>
<?php
if($_GET['dw']=="yes")
{
print '
<table border="0" align="center" width="500">
<tr id="thr">
<th>File ID</th>
<th>File Name</th>
<th>File Ext</th>
<th>Date & Time</th>
</tr>';
mysql_connect(" localhost","roo t","") or die("Sever connection error");
mysql_select_db ("file") or die ("Database error");
$sel=mysql_quer y("select * from file_tb") or die("Table Error");
while($r=mysql_ fetch_array($se l))
{
print '<tr id="trr">';
print '<td>'.$r['id'].'</td>';
print '<td><a href="download. php?action=view &id='.$r['id'].'">'.$r['file_name'].'</a></td>';
print '<td>'.$r['ext'].'</td>';
print '<td>'.$r['date_time'].'</td>';
print '</tr>';
}
print '</table>';
}
?>
<?php
if (isset($_GET['action']) && ($_GET['action'] == "view"))
{
$fid=$_GET['id'];
mysql_connect(" localhost","roo t","") or die("Sever connection error");
mysql_select_db ("file") or die ("Database error");
$sel=mysql_quer y("select * from file_tb") or die("Table Error");
while($r=mysql_ fetch_array($se l))
{
if($r['id']==$fid)
{
$fi=$r['file'];
$ab="files/".$r['file_name'];
$fp=fopen($ab," w+") or die("file error");
fwrite($fp,$fi) ;
print '<img src="';
print $ab;
print '" >';
print '<h3 align="center"> File Downloaded in <a href="files">Fi les</a> Directory</h3>';
}
}
}
?>
DATABASE.php
<title>MYSQL Table Installation</title>
<?php
print '<h2 align="center"> MYSQL Table Installation</h2>';
mysql_connect(" localhost","roo t","") or die("Sever connection error");
mysql_query("CR EATE DATABASE IF NOT EXISTS file") or die("Database Already Exists");
mysql_select_db ("file");
$q="CREATE TABLE IF NOT EXISTS `file_tb` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`file_name` VARCHAR( 20 ) NOT NULL ,
`file` LONGBLOB NOT NULL ,
`ext` VARCHAR( 5 ) NOT NULL ,
`date_time` DATETIME NOT NULL
) ENGINE = MYISAM
";
mysql_query($q) or die("Table Error");
print '<h3 align="center"> Installation Complete</h3>';
?>
first run database.php, then run main.php.
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment