السلام عليكم اخواني الافاضل اريد تعديل هذا الكود لكي يرفع اكثر من صورة بالقاعدة مع الخبرة
بمعني اريد ان اتيح اضافة صور اضافية مع الخبر باستثناء الصورة الاساسية للخبر
وكل ما اريد اضافة صورة اضيف حقل جديد لنقول مثلا 10 صور
قمت بعمل تصغير تلقائى للصورة الان اريد فقط اضافة اكثر من صورة وادخالهم بالقاعد
وداله اظهارهم مع الخبر فى جدول مستقل مثلا يعني فكهم
صفحة add اضافة الاخبر
ملاحظة حقل ال pic هيا الصورة الاساسية للخبر اما الحقول المخفيه img هيا الاضافيه
<script type="text/javascript">
count=1;
function add_file_field()
{
if(count<11)
{
var container=document.getElementById('file_container');
var file_field=document.createElement('input');
file_field.name='img[]';
file_field.type='file';
file_field.class='TEXTPUT3';
container.appendChild(file_field);
var br_field=document.createElement('br');
container.appendChild(br_field);
count++;
}
}
</script>
<FORM name=send action="insert.php" method=post enctype="multipart/form-data">
<table border="1" width="100%">
<tr>
<td colspan="2">العنوان</td>
<td>
<input class=TEXTPUT name="titel" size="39" dir="rtl" ></td>
</tr>
<tr>
<td colspan="2">الصورة الاساسية</td>
<td>
<input class=TEXTPUT type="file" name="pic" size="24" ></td>
</tr>
<tr>
<td>الصور الاضافية</td>
<td><a href="javascript:void(0);" onClick="add_file_field();">اضافة صوة اخرى</a> </td>
<td> <div id="file_container">
</div>
</td>
</tr>
<tr>
<td colspan="2">التفاصيل</td>
<td>
<textarea rows="4" name="note" cols="25" ></textarea></td>
</tr>
</table>
</form>صفحة insert الخبر
<?php
function resize($image, $new_name, $width, $height, $ext)
{
$radio = imagesx($image) > imagesy($image) ? imagesx($image) / $width : imagesy($image) / $height;
if (imagesx($image) > imagesy($image))
{
$height = imagesy($image) / $radio;
}
elseif (imagesy($image) > imagesx($image))
{
$width = imagesx($image) / $radio;
}
$tmp_image = imagecreatetruecolor($width, $height);
imagefill($tmp_image, 0, 0, 0xfffff);
imagecopyresampled($tmp_image, $image, 0, 0, 0, 0, $width, $height, $width * $radio, $height * $radio);
if($ext == 'gif')
{
$image = imagegif($tmp_image, $new_name);
}
elseif($ext == 'png')
{
$image = imagepng($tmp_image, $new_name);
}
elseif($ext == 'jpg')
{
$image = imagejpeg($tmp_image, $new_name);
}
}
if(is_uploaded_file($_FILES['pic']['tmp_name']))
{
$file_name = basename($_FILES['pic']['name']);
$exp = explode('.', $file_name);
$ext = strtolower($exp[count($exp)-1]);
$picu = "file_" . time() . '.' .$ext;
$file_path = "pic/" . $picu;
if ($ext == 'jpg' OR $ext == 'gif' OR $ext == 'png')
{
move_uploaded_file($_FILES['pic']['tmp_name'], $file_path);
if($ext == 'gif')
{
$image = imagecreatefromgif($file_path);
}
elseif($ext == 'png')
{
$image = imagecreatefrompng($file_path);
}
elseif($ext == 'jpg')
{
$image = imagecreatefromjpeg($file_path);
}
resize($image, 'pic/small_'. $picu, 320, 240, $ext);
unlink($file_path);
}
$insert = "insert into news (titel,picat,files,note) values ('$titel','small_$picu','img[]','$note')";
$Result = mysql_query($insert);
if ($Result)
{
echo "تم الاضافة بنجاح";
}
}
else
{
echo 'لم يتم رفع أي ملف';
}
?>