first this error is happening in IE7 and IE6
second the full source code i created is :
Code: Select all
<?php
require("connect.php");
require("head.php");
if($_POST["submit"]){
$igroup = $_POST["imggroup"];
$upload_file;
$msg = "";
if(!($_POST["imgname"] == "" || $_POST["imgdes"] == "")){
$iname = $_POST["imgname"];
$ides = $_POST["imgdes"];
$upload_file = true;
}else{
$upload_file = false;
$msg .= "There is some feilds are empty .";
}
if($_FILES["userfile"] == ""){
$upload_file = false;
$msg .= "please choose an image file to upload<br>";
}else{
$userfile = $_FILES["userfile"];
$userfile_name = $_FILES["userfile"]["name"];
$userfile_size = $_FILES["userfile"]["size"];
$userfile_type = $_FILES["userfile"]["type"];
}
if(!($userfile_type == "image/jpg" or $userfile_type == "image/jpeg" or $userfile_type == "image/png" or $userfile_type == "image/gif")){
$msg .= "<br>image types that allowed are : jpg & jpeg & gif & png";
$upload_file = false;
}else{
$upload_file = true;
}
if($userfile_size > 1024000){
$msg .= "Max file size is 1024 KB .";
$upload_file = false;
}else{
$upload_file = true;
}
// code for getting rows number of the table
$q = "SELECT * FROM `images`";
$res = mysql_query($q);
$row_num = mysql_num_rows($res);
$path;
if($userfile_type == "image/jpg"){
$path = strtolower("upload/".($row_num++).".jpg");
}
if($userfile_type == "image/jpeg"){
$path = strtolower("upload/".($row_num++).".jpeg");
}
if($userfile_type == "image/gif"){
$path = strtolower("upload/".($row_num++).".gif");
}
if($userfile_type == "image/png"){
$path = strtolower("upload/".($row_num++).".png");
}
if($upload_file == false){
echo $msg;
}else{
if(move_uploaded_file($userfile["tmp_name"], $path)){
echo "<br>";
echo "file uploaded successfuly";
chmod("{$path}",0777);
}else{
echo "error in saving file";
}
}
$n_width = 70;
$n_height = 100;
// thum dir based on upload dir
$thum = str_replace("upload/","thum/",$path);
if($userfile_type == "image/gif"){
$im = ImageCreateFromGIF($path);
$width = ImageSx($im);
$height = ImageSy($im);
$r = $height / $width;
$h = 120;
$w = 120 * $r;
$new_image = imagecreatetruecolor($h, $w);
imageCopyResized($new_image,$im,0,0,0,0,$h,$w,$width,$height);
if(function_exists("imagegif")){
ImageGIF($new_image,$thum);
}elseif(function_exists("imagejpeg")){
ImageJPEG($newimage,$thum);
}
chmod("{$thum}",0777);
}
if($userfile_type=="image/jpeg" or $userfile_type=="image/jpg"){
$im=ImageCreateFromJPEG($path);
$width=ImageSx($im);
$height=ImageSy($im);
$r = $height / $width;
$h = 120;
$w = 120 * $r;
$newimage=imagecreatetruecolor($h,$w);
imageCopyResized($newimage,$im,0,0,0,0,$h,$w,$width,$height);
ImageJpeg($newimage,$thum);
chmod("{$thum}",0777);
}
if($userfile_type=="image/png"){
$im=ImageCreateFromPNG($path);
$width=ImageSx($im);
$height=ImageSy($im);
$r = $height / $width;
$h = 120;
$w = 120 * $r;
$newimage=imagecreatetruecolor($h,$w);
imageCopyResized($newimage,$im,0,0,0,0,$h,$w,$width,$height);
ImagePng($newimage,$thum);
chmod("{$thum}",0777);
}
if($upload_file == true){
// add full size image and thum paths to the database
$q = "INSERT INTO `images` ( `id` , `img` , `thum` , `name` , `descripe` , `group` )
VALUES (NULL , '{$path}', '{$thum}' , '{$iname}' , '{$ides}' , '{$igroup}' )";
$res = mysql_query($q);
if($res){
echo "<!--query done ok-->";
}else{
echo "<!--query NOT done-->";
}
}
}
?>
<form action="upload.php" method="post" enctype="multipart/form-data" >
<table align="center" border="0" cellspacing="10">
<tr>
<td>choose an image file : </td>
<td><input name="userfile" type="file" size="50" /></td>
</tr>
<tr>
<td>name : </td>
<td><input type="textfield" name="imgname" size="50" /></td>
</tr>
<tr>
<td>description : </td>
<td><input type="textfield" name="imgdes" size="50" /></td>
</tr>
<tr>
<td>choose a group : </td>
<td>
<select name="imggroup">
<?php
// get list of groups from the DB
$q = "SELECT * FROM `grp`";
$res = mysql_query($q);
if($res){
while($row = mysql_fetch_array($res)){
echo "<option value=\"". $row["id"]."\">".$row["gn"]."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="submit" value="upload" type="submit"/>
</td>
</tr>
</table>
</form>
<br>
---------------------------------------------------
<br>
</div>
</body>
</html>