الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

اريدتعديل على هذا الكود ليرفع اكثر من صورة

بدأه fatmaali في 11 ديسمبر 2013 · 21 رد · 756 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم اخواني الافاضل اريد تعديل هذا الكود لكي يرفع اكثر من صورة بالقاعدة مع الخبرة

 

بمعني اريد ان اتيح اضافة صور اضافية مع الخبر باستثناء الصورة الاساسية للخبر

 

وكل ما اريد اضافة صورة اضيف حقل جديد لنقول مثلا 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 'لم يتم رفع أي ملف';
}
?>

تم تعديل هذه المشاركة بواسطة fatmaali في 11 ديسمبر 2013 في 21:43

#2

معقولة يا اخوان 20 مشاهدة ولا رد لحل المشكل :(

#3

<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='pic[]';

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>

<tr>

<td><input type='submit' name='submit' /></td>

</tr>

</table>

</form>

<?php

if(isset($_POST['submit'])){

$num = count($_FILES['pic']['tmp_name']);

if($num >0 ){

for($i=0;$i<$num;$i++){

if(is_uploaded_file($_FILES['pic']['tmp_name'][$i]))

{

$file_name = basename($_FILES['pic']['name'][$i]);

$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')

{

$filenmae = $_FILES['pic']['tmp_name'][$i];

move_uploaded_file($_FILES['pic']['tmp_name'][$i], $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,files,note) values ('$titel','$filenmae','$note')";

$Result = mysql_query($insert);

if ($Result)

{

echo "تم الاضافة بنجاح";

}

}

}

}

}

?>

تم تعديل هذه المشاركة بواسطة eng_badr في 13 ديسمبر 2013 في 01:21

1
#4

بارك الله فيك احي الفاضل

 

 

طيب كيف اظهر الصور وافكهم عن بعض

 

يعني فى صفحة الخبر نفسه

 

كيف اظهر الصور المضافة

 

والجدول الذى يتم تخزين الصور فيه يكون بصيغه معينه ام لا ؟
 

بمعني

 

varchar او  BLOB او CHAR

 

 

وعندما اريد اظهارهم في الخبر كيف يتم اخارجهم وفكهم فى الخبر

تم تعديل هذه المشاركة بواسطة fatmaali في 13 ديسمبر 2013 في 01:35

#5

الافضل عمل فولدر لكل حجم للصور 

        resize($image, 'small/'. $picu, 60, 50, $ext);
        resize($image, 'mid/'. $picu, 500, 500, $ext);
        resize($image, 'big/'. $picu, 800, 800, $ext);

ويكون اسم الصور واحد مع اختلاف اسماء الفولدرات

 

اما بالنسبة لتخزين الصور فالاضل ان تكون VARCHAR 255

1
#6

تمام اخي طيب كيف استخرجهم  واعرضهم بالخبر

 

لنفرض مضفتش غير 5 صور بس او 6 او 10 او 2

 

 

سوالى بس طريقة استخراجهم من الجدول واعرضهم مع الخبر

تم تعديل هذه المشاركة بواسطة fatmaali في 13 ديسمبر 2013 في 01:43

#7

عرض الصور

$query = mysql_query("SELECT * FROM news ORDER BY id DESC");
while($row = mysql_fetch_array($query)){
	$imagename = $row['files'];
	echo "<img src='small/".$imagename."' /><br />";  //الصورة الكييرة
	echo "<img src='mid/".$imagename."' /><br />";		// الصورة المتوسطة
	echo "<img src='big/".$imagename."' /><br />";     // الصورة الصغيرة
}
1
#8

شاكرة ومقدر جدا اخي ساقوم بتجربة الكود كامل واي استفسار ساقوم بذكرة لك وفقك الله اخي الفاضل

تم تعديل هذه المشاركة بواسطة fatmaali في 13 ديسمبر 2013 في 01:48

#9

الافضل عمل جدول اخر اسمو photos

ونربطة بجدول ال news عن طريق ال news_id

#10

وكيف يكون امر الادخال حينها اخي الفاضل علمها بان الخبر يكون كامل بصفحة واحدة ؟؟؟ يعني كيف اعمل ادخال جدولين واحد للخبر واخر للصور ويكون واخد ايدي الخبر الى هيظهر فيه اثناء رفعه ؟؟؟

 

 

لان طريقه حضرتك تقول ان يتم الرفع بعد اضافة الخبر حتى يكون الخبر اخذ ايبي ثابت بعدها نقوم برفع صور ونختار الخبر مثلا من قائمة منسدله ثم الرفع لكن اراها كبيرة قليلا اذا في طريقه اخرى تقصدها ارجو التوضيح

 

ارجو التوضيح ولو فى المثال

تم تعديل هذه المشاركة بواسطة fatmaali في 13 ديسمبر 2013 في 01:54

#11

اخر تعديل بعد اضافة جدول الصور

<?php
if(isset($_POST['submit'])){

$num = count($_FILES['pic']['tmp_name']);
if($num >0 ){
	for($i=0;$i<$num;$i++){

if(is_uploaded_file($_FILES['pic']['tmp_name'][$i]))
{
    $file_name = basename($_FILES['pic']['name'][$i]);
        $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')
    {
	$filenmae = $_FILES['pic']['tmp_name'][$i];
        move_uploaded_file($_FILES['pic']['tmp_name'][$i], $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,files,note) values ('$titel','$filenmae','$note')";
  
   $Result = mysql_query($insert);
    if ($Result)
    {
        echo "تم الاضافة بنجاح";
    }
	
	if(isset($insert)){
		$news_id = mysql_insert_id();
		
		$insert_photos = mysql_query("INSERT INTO (news_id,photo) VALUES ('$news_id','$filenmae')");
	}
	
}
}

}

}
?>
#12

mysql_insert_id()

هذه الدالة بتجيب اخر id تم ادخاله فى قاعدة البيانات

#13

طريقة جميله اخي الكريم بس هل يحدث مشكلة ان كان هناك 2 اعضاء يدخلون خبر بنفس الوقت ؟؟؟ ولما يستدعي ايدي يستدعي ايدي اخر ؟؟

 

 

كمان فى استفسار صغير

 

اذا حبيت يكون هناك صورة ثابته للخبر باستناء الصور العشرة كيف يكون الوضع ؟ بمعنى ان يكون اساسي صور الخبر والعنوان والتفاصيل

 

الغير اساسى هم الصور الاضافية

 

بحيس يكون الصورة الاساسيه فى حقل مستقل يعني ان كان الصور الاضافية في FILES  تكون الاساسية PICS مثلا وويكون المستغرض الخاص بهاا فى html ثابت بدل files[]     يكون pics

#14

لن يحدث اى مشاكل حتى لو اكتر من عضور فى نفس الوقت يدخلون اخبار لان داله 

mysql_insert_id() تاتى باخر ايديه تم ادخالو فى نفس الكويرى اللى تمت قبلها فى نفس الصفحة

 

لو عايزة صورة رئيسية للخبر والباقى صور اضافية يمكن عمل 

field للصورة الرئيسية فى جدول ال news 

والباقى فى جدول ال photos

<input type="file" name="main_imge" />

تم تعديل هذه المشاركة بواسطة eng_badr في 13 ديسمبر 2013 في 02:09

#15

وضعت صورة اساسيه بالطريقة التى ذكرتها لكن لم تعمل

 

<input type="file" name="picmain" />

<?php
if(isset($_POST['submit'])){

$num = count($_FILES['pic']['tmp_name']);
if($num >0 ){
	for($i=0;$i<$num;$i++){

if(is_uploaded_file($_FILES['pic']['tmp_name'][$i]))
{
    $file_name = basename($_FILES['pic']['name'][$i]);
        $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')
    {
	$filenmae = $_FILES['pic']['tmp_name'][$i];
        move_uploaded_file($_FILES['pic']['tmp_name'][$i], $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,picmain,note) values ('$titel','$picmain','$note')";
  
   $Result = mysql_query($insert);
    if ($Result)
    {
        echo "تم الاضافة بنجاح";
    }
	
	if(isset($insert)){
		$news_id = mysql_insert_id();
		
		$insert_photos = mysql_query("INSERT INTO (news_id,photo) VALUES ('$news_id','$filenmae')");
	}
	
}
}

}

}
?>

هل هناك شيئ ناقص بنقل الصور الى المجلدات او اسم الحقل الجديد ؟؟

#16

//اظهار الصور

$query = mysql_query("SELECT * FROM news ORDER BY id DESC");

while($row = mysql_fetch_array($query)){

$query_photos = mysql_query("SELECT * FROM photos WHERE news_id='".$row['id']."' ORDER BY id ASC ");

while($row_photos = mysql_fetch_array($query_photo)){

$imagename = $row_photos['photo'];

echo "<img src='small/".$imagename."' /><br />"; //الصورة الكييرة

echo "<img src='mid/".$imagename."' /><br />"; // الصورة المتوسطة

echo "<img src='big/".$imagename."' /><br />"; // الصورة الصغيرة

}

}

#17

// سيتم ادخال الصورة الرئيسية على حدة الاول لوحدها

if(is_uploaded_file($_FILES['picmain']['tmp_name']))

{

$picmain = basename($_FILES['picmain']['name']);

$exp = explode('.', $picmain);

$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 = "insert into news (titel,picmain,note) values ('$titel','$picmain','$note')";

#18

لم اقصد اظهار الصور الغير اساسيه انا قصدت رفع الصورة الاساسيه  ووضعها بحقل النيوز بخلاف الصور الفرعيه

<input type="file" name="picmain" />

#19

الكود الكامل بعد التعديل 

<?php
if(isset($_POST['submit'])){




// سيتم ادخال الصورة الرئيسية على حدة الاول لوحدها

if(is_uploaded_file($_FILES['picmain']['tmp_name']))
{
    $picmain = basename($_FILES['picmain']['name']);
        $exp = explode('.', $picmain);
    $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);
    }

	
	////////////////////// باقى الصور

$num = count($_FILES['pic']['tmp_name']);
if($num >0 ){
	for($i=0;$i<$num;$i++){

if(is_uploaded_file($_FILES['pic']['tmp_name'][$i]))
{
    $file_name = basename($_FILES['pic']['name'][$i]);
        $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')
    {
	$filenmae = $_FILES['pic']['tmp_name'][$i];
        move_uploaded_file($_FILES['pic']['tmp_name'][$i], $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,picmain,note) values ('$titel','$picmain','$note')";
  
   $Result = mysql_query($insert);
    if ($Result)
    {
        echo "تم الاضافة بنجاح";
    }
	
	if(isset($insert)){
		$news_id = mysql_insert_id();
		
		$insert_photos = mysql_query("INSERT INTO (news_id,photo) VALUES ('$news_id','$filenmae')");
	}
	
}
}

}

}
?>
#20

تم بنجاح اخي الفاضل  شاكرة جدا لك وجعله الله في ميزان حسناتك

 

جاري التجربة على الصفحة كامله واى شيئ بسالك فيه اخي

تم تعديل هذه المشاركة بواسطة fatmaali في 13 ديسمبر 2013 في 02:31

#21

حاليا يطلع الايرور دا اخي الفاضل

 

 

Parse error: syntax error, unexpected $end in C:\AppServ\www\up\insert.php on line 95

<?php
if(isset($_POST['submit'])){

 


// سيتم ادخال الصورة الرئيسية على حدة الاول لوحدها

if(is_uploaded_file($_FILES['picmain']['tmp_name']))
{
    $picmain = basename($_FILES['picmain']['name']);
        $exp = explode('.', $picmain);
    $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);
    }

	
	////////////////////// باقى الصور

$num = count($_FILES['pic']['tmp_name']);
if($num >0 ){
	for($i=0;$i<$num;$i++){

if(is_uploaded_file($_FILES['pic']['tmp_name'][$i]))
{
    $file_name = basename($_FILES['pic']['name'][$i]);
        $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')
    {
	$filenmae = $_FILES['pic']['tmp_name'][$i];
        move_uploaded_file($_FILES['pic']['tmp_name'][$i], $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, 'temp/temp_'. $picu, 320, 240, $ext);
        unlink($file_path);
    }
    include("config.php");

   $insert = "insert into news (titel,picmain,note) values ('$titel','$picmain','$note')";
  
   $Result = mysql_query($insert);
    if ($Result)
    {
        echo "تم الاضافة بنجاح";
    }
	
	if(isset($insert)){
			include("config.php");

		$news_id = mysql_insert_id();

		$insert_photos = mysql_query("INSERT INTO photo (news_id,photo) VALUES ('$news_id','$filenmae')");
	}
	
}
}

}
}

?>
<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='pic[]';
file_field.type='file';
file_field.class='TEXTPUT3';
container.appendChild(file_field);
var br_field=document.createElement('br');
container.appendChild(br_field);
count++;
}
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">


<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="picmain" 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>
<tr>
<td><input type='submit' name='submit' /></td>
</tr>
</table>
</form>
#22

حاليا يطلع خطاء اخي الفاضل بهذا السطر

 

 

Parse error: syntax error, unexpected $end in C:\AppServ\www\up\insert.php on line 95

<?php
if(isset($_POST['submit'])){

 


// سيتم ادخال الصورة الرئيسية على حدة الاول لوحدها

if(is_uploaded_file($_FILES['picmain']['tmp_name']))
{
    $picmain = basename($_FILES['picmain']['name']);
        $exp = explode('.', $picmain);
    $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);
    }

	
	////////////////////// باقى الصور

$num = count($_FILES['pic']['tmp_name']);
if($num >0 ){
	for($i=0;$i<$num;$i++){

if(is_uploaded_file($_FILES['pic']['tmp_name'][$i]))
{
    $file_name = basename($_FILES['pic']['name'][$i]);
        $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')
    {
	$filenmae = $_FILES['pic']['tmp_name'][$i];
        move_uploaded_file($_FILES['pic']['tmp_name'][$i], $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, 'temp/temp_'. $picu, 320, 240, $ext);
        unlink($file_path);
    }
    include("config.php");

   $insert = "insert into news (titel,picmain,note) values ('$titel','$picmain','$note')";
  
   $Result = mysql_query($insert);
    if ($Result)
    {
        echo "تم الاضافة بنجاح";
    }
	
	if(isset($insert)){
			include("config.php");

		$news_id = mysql_insert_id();

		$insert_photos = mysql_query("INSERT INTO photo (news_id,photo) VALUES ('$news_id','$filenmae')");
	}
	
}
}

}
}

?>
<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='pic[]';
file_field.type='file';
file_field.class='TEXTPUT3';
container.appendChild(file_field);
var br_field=document.createElement('br');
container.appendChild(br_field);
count++;
}
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">


<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="picmain" 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>
<tr>
<td><input type='submit' name='submit' /></td>
</tr>
</table>
</form>

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…