Forum Moderators: coopster

Message Too Old, No Replies

Image upload

         

dico

11:45 am on Sep 7, 2009 (gmt 0)

10+ Year Member



hi friends i am working on an entrance system. i have created and tested all the pages, and they are working fine.
I have a little challenge in the upload form page. when different users uploads an image during registration it uploads, when they log in every user keeps seeing one particular image.
please i need an assistance here.
The codes are:

<?php
include("library/connection.php");
if($_FILES['ui']['name']!=''){
$fileName = $_FILES['ui']['name'];
$tmpName = $_FILES['ui']['tmp_name'];
$fileSize = $_FILES['ui']['size'];
$fileType = $_FILES['ui']['type'];
$source = $_FILES['ui']['tmp_name'];
$target = "images/".$fileName;
$target_path = "images/";
$target_path = $target_path.$fileName.'.jpg';
if(move_uploaded_file($_FILES['ui']['tmp_name'], $target_path)) {
echo "The file ".$fileName.
".jpg has been uploaded!";
} else{
echo "There was an error uploading the file, please try again!";
}
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
}
?>

<html>
<head>
<style type="text/css">

#picturearea{
filter:alpha(opacity=100);
-moz-opacity:0;
}
</style>
<title>Upload image Here</title>
<link rel="stylesheet" type="text/css" href="images/css.css">
<link rel="stylesheet" type="text/css" href="images/style.css">

<style type="text/css">
<!--
.style2 {color: #FFFFFF; font-weight: bold; }
.style3 {color: #FFFFFF}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" bgcolor="#999999" style="background-color: #808080" onLoad="meto()">
<font color="#660000"> <?= $errmsg?> </font>
<center>
<b><?= $title ?></center>
<span class="style3"></span>

<table align="center" border="0" cellpadding="0" cellspacing="0" width="900">

<tbody><tr>

<td class="maintop">

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td height="80" bgcolor="#006600" class="maintopright" style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color:#006600">
<div class="maintopright">&nbsp;&nbsp;
<div style="position: absolute; width: 559px; height: 31px; z-index: 1; left: 376px; top: 32px" id="layer1">
<b>
<span>
<font color="#FFFFFF" style="font-size: 15pt; "><b><span><font color="#FFFFFF" style="font-size: 15pt; "><span style="font-weight: 400"><img border="0" src="images/coa.JPG" width="37" height="34"></span></font></span></b>COMMON ENTRANCE PASSPORT UPLOAD<br>
</font>
<span style="font-weight: 400">
<font color="#FFFFFF" style="font-size: 8pt; font-style:italic">
Common Entrance application...powered by Ekanem and mbong</font></span></span></b></div>
</div> </td>
</tr>
</tbody></table>
</td>

</tr>

<tr>

<td class="main" align="left" valign="top"><div>

<table border="0" cellpadding="0" cellspacing="0" width="100%">

<tbody><tr>

<td class="maincenter" align="center" valign="top" width="900" style="background-color: #006600"><div style="margin-top: 2px; margin-bottom: 2px;">

<table border="0" cellpadding="6" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="border-top: 1px solid rgb(153, 153, 153); font-size: 5px; background-color: rgb(255, 255, 255);" height="1"></td>
</tr>
</tbody></table>
<table border="0" cellpadding="5" cellspacing="0" width="100%">

<tbody><tr>
<td class="midinfo" valign="top" width="19%" rowspan="2" style="background-color: #F1F1F1">
<div id="menu">
<ul>
<li>
<ul>

&nbsp;&nbsp;&nbsp; e-examination portal
</ul>
<hr>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;<font size="+1" color="#660000"> <marquee scrollamount="3" direction="left">UPLOAD YOUR PASSPORT WITH A RED COLOUR BACKGROUND; ELSE YOUR ENTRY WILL NOT BE ACCEPTED</marquee></font></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></li>

</td>

</tr>



<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<font face="Arial Special G1" size="2" color="#FFFFFF">&nbsp; UPLOAD PASSPORT HERE:</font>
<td width="300">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="ui" type="file" id="ui">
</td>
<td width="80"><input name="ui" type="submit" class="box" id="ui" value=" Upload "></td>
</tr>
</table>
</form>
<dl>
<div align="center">

<a href="index.php" class="style2">Back</a>
<b>
<?php
echo "¦";
?>
</b>
<a href="usermain.php" class="style2">Finish Registeration</a>
<b>
<?php
echo "¦";
?>
</b></div>
</dl>

</body>
</html>


That of the view image is:

<?php
{
echo '<table border="1"><tr><td>
<div style="float: right;"><img src="images/'.$fileName.'.jpg" width="150px" height="150px" /></div>
</div></td></tr></table>';
}?>

ALKateb

9:12 am on Sep 8, 2009 (gmt 0)

10+ Year Member



i'm not sure i got what u mean
but u said when they login they all are getting the same picture right?
how exactly are u retriving the picture's name from the database? there must be something wrong with that
ur code needs a little work anyway .. first of all u need to change the name of the file since different users might upload different pictures with the same name
this will overwrite the old pic! so i suggest u changeing the name of the picture to a random name or u can use the timestamp as a name for the file
and u should make a check there for the file type
if ($_FILES["ui"]["type"] == "image/jpeg") or image/jpg or image/jpeg (for IE!)

and consider making a check on the file size if u want to .. dont rely on the hidden field MAX_FILE_SIZE cos it can be manipulated
do the check like this
if($_FILES["ui"]["size"] > 2000000)

ur code must work fine but u just have to make sure of the way ure retrieving the information from the database if u post it i guess i can figure out what's wrong with it
good luck

dico

3:40 pm on Sep 9, 2009 (gmt 0)

10+ Year Member



I got it!
Thanks alot