473,385 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how can image be uploaded

I want that a user can upload his image .
How can his image be stored in the database and can be retrieved from database?
Mar 9 '07 #1
4 1213
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.
Mar 9 '07 #2
ronverdonk
4,258 Expert 4TB
Look at this reply to a similar question I just posted http://www.thescripts.com/forum/post2424480-4.html

Ronald :cool:
Mar 9 '07 #3
DavidPr
155 100+
I read that thread and downloaded the zip files. The script works great, but how do I display the pictures?
Mar 18 '07 #4
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.php?up=yes"><strong>
Upload File
</strong> </a> </td>
</tr>
<tr id="trr" >
<td align="center"><a href="download.php?dw=yes"><strong>
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="multipart/form-data" >
<table width="450" border="0" align="center" ><stron>
<tr id="trr">
<th width="207">File Upload </th>

<td width="233"><input type="file" name="uplfile" value="sss"></td></tr>

<tr id="trr">
<td>&nbsp;</td>
<td>&nbsp;</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_FILES['uplfile']['name']))

if(@rename($HTTP_POST_FILES['uplfile']['tmp_name'],$HTTP_POST_FILES['uplfile']['name']))
$flag=1;
else
$flag=0;

}

if($flag==1)
{

$file_u=$HTTP_POST_FILES['uplfile']['name'];
$da=date("Y-m-d ",time() + (34200)).date("H:i:s",time() + (34200));

mysql_connect("localhost","root","") or die("Sever connection error");

mysql_select_db("file") or die ("Database error");
$val = fread(fopen($file_u, "r+"), filesize($file_u)+1);
if (!empty($val))
{

$val = '0x' . bin2hex($val);
$ext=substr($HTTP_POST_FILES['uplfile']['name'],strlen($HTTP_POST_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_FILES['uplfile']['name']);

}
}
?>


download.php

<title>Download 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","root","") or die("Sever connection error");

mysql_select_db("file") or die ("Database error");
$sel=mysql_query("select * from file_tb") or die("Table Error");
while($r=mysql_fetch_array($sel))
{
print '<tr id="trr">';
print '<td>'.$r['id'].'</td>';
print '<td><a href="download.php?action=view&amp;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","root","") or die("Sever connection error");
mysql_select_db("file") or die ("Database error");
$sel=mysql_query("select * from file_tb") or die("Table Error");
while($r=mysql_fetch_array($sel))
{
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">Files</a> Directory</h3>';
}
}

}
?>


DATABASE.php

<title>MYSQL Table Installation</title>


<?php
print '<h2 align="center">MYSQL Table Installation</h2>';
mysql_connect("localhost","root","") or die("Sever connection error");
mysql_query("CREATE 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.
Mar 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: Mark | last post by:
Hi all, I want to be able to resize an image that a user has uploaded. I have the image upload working as well as the image resize. When I go to delete the original uploaded file (I want to...
11
by: bissatch | last post by:
Hi, I am trying to upload an image, create a new file based on that image and then store the base64 encoded image data in a database. I dont really know where my code is going wrong so I will...
0
by: Satish Appasani | last post by:
Hi: I have a ASP.NET form with Web layout which I've achieved using panels. In one of the tab I have a File control to upload Images. When I put a file in the file control and move to another...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
8
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a...
14
by: =?Utf-8?B?U2FtdWVs?= | last post by:
Hi, I have a web app that allows others to upload files, and the problem is that if I allow users to upload image files, fake image can be uploaded and cause XSS issues. In the app, I do...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.