في رأس صفحة الفورم اكتب :
كود PHP:
<script language="JavaScript">
<!--
function next()
{
var opn=window.open("url.php",'',"width=500, height=400");
}
</script>
وفي داخل الفورم أضف :
كود PHP:
<input type="button" value="تحميل الملف" onclick="next()"/>
<input name="attachment" type="attached" value="http://www." id="attachment" >
ثم افتح صفحة جديدة باسم url.php واكتب فيها الكود التالي :
كود PHP:
<script type="text/javascript">
function submitValueBack(){
window.opener.document.getElementById("attachment").value = document.getElementById("url").value;
window.opener.document.getElementById('newwindow').disabled = 'disabled';
window.close();
}
</script>
?>
/*
#######################################################################################
# class Name: AksidSars Swalif.net/softs #
# المبرمج : Nadorino Swalif.net/softs #
# E-mail : Elbachiri@Gmail.com Swalif.net/softs #
# تاريخ البرمجة : مساء يوم الجمعة 15/12/2006 Swalif.net/softs #
# الترخيص: C المرجو استخدامه في ما يرضي الله Swalif.net/softs #
# V 1.0 15/12/2006 16:55 Swalif.net/softs #
########################################################################################
*/
class AksidSars
{
var $asarsi;
var $amchan;
var $thwara;
var $ansaq;
var $isam;
var $baddarisam;
var $linksite;
function thwara(){ //thwara بداية
echo'<table align="center"><tr><td><FORM action='.$this->amchan.' method=post encType=multipart/form-data>';
for($i=0;$i<$this->thwara;$i++){ //بداية for
echo '<input type="file" name="file'.$i.'"><br>';
} // نهاية for
echo '<center><input type="submit" value=" تحميل الملفات "></form></td></tr></table>';
} //thwara نهاية
function aksid(){ //Aksid بداية
if(file_exists($this->asarsi)){ //بداية التحقق من المجلد هل هو موجود ام لا
//يبقى فارغا اذا كان المجلد موجود
for($i=0;$i<$this->thwara;$i++){ // for بداية
$this->baddarisam=explode(".",$_FILES['file'.$i]['name']);
$this->baddarisam=$this->baddarisam[count($this->baddarisam)-1];
$zaid=time()+$i;
$this->baddarisam=$this->isam.$zaid.".".$this->baddarisam;
if(empty($_FILES['file'.$i]['tmp_name'])){ // التحقق من الملف هل هو فارغ
}
else
{
if(file_exists($this->asarsi.'/'.$_FILES['file'.$i]['name'])){ // if بداية total
echo '<table align="center" border="1" cellspacing="0" bordercolordark="white" bordercolorlight="black"><tr><td width="500">هذا الملف موجود مسبقا</td></tr></table>';
}
elseif(!in_array(strrchr($_FILES['file'.$i]['name'],'.'),$this->ansaq)){
echo '<table align="center" border="1" cellspacing="0" bordercolordark="white" bordercolorlight="black"><tr><td width="500">هذه الصيغة غير مدعومة في مركزنا</td></tr></table>';
}
else
{
$file=move_uploaded_file($_FILES['file'.$i]['tmp_name'], $this->asarsi."/".$this->baddarisam);
if($file){ //if بداية
echo'<table align="center" border="1" cellspacing="0" bordercolordark="white" bordercolorlight="black"><tr><td width="500">ممتاز.. لقد تم تحميل الملف بنجاح<br>';
echo'<a href="'.$this->linksite.$this->asarsi."/".$this->baddarisam.'" target="_blank">'.$this->baddarisam.'</a><br>';
echo'<textarea cols=60 rows=1>'.$this->linksite.$this->asarsi."/".$this->baddarisam.'</textarea></td></tr></table>';
}
else
{
echo'<table align="center" border="1" cellspacing="0" bordercolordark="white" bordercolorlight="black" ><tr><td width="500">خطأ... لم يتم تحميل الملف لاسباب غير معروفة</td></tr></table>';
} // if نهاية
} // if نهاية total
} // التحقق من الملف هل هو فارغ نهاية
} // نهاية for
} // نهاية التحقق من الملف
else // نهاية التحقق من الملف
{ // نهاية التحقق من الملف
$jadid=mkdir($this->asarsi);
if($jadid){ //بداية التحقق من انشاء مجلد جديد
echo"لقد تم انشاء مجلد جديد";
}
else
{
echo"لم يتم انشاء مجلد جديد لاسباب لا اعرفها";
} // نهاية التحقق من انشاء ممجلد جديد
} // نهاية التحقق من الملف
} //Aksid نهاية
};
$tahmil= new AksidSars; //تعريف الكائن
/*
// لتغيير اسم الملف \\
$tahmil->tashfir="md5"; = Nadorino-450ce46498.swf
$tahmil->tashfir="time"; = Nadorino-1178575798.swf
$tahmil->tashfir=""; = ترك اسم الملف الحقيقي
*/
$tahmil->tashfir="";
$tahmil->linksite="http://localhost/"; //رابط الموقع
$tahmil->asarsi="Nadorino"; //سم المجلد الذي وضع فيه الملفات (ان لم يكون موجود مسبقا سيتم انشاءه اليا
$tahmil->isam="Nadorino-"; // الاسم الذي يسيق الملفات سيتم تغيير اسماء الملفات اليا Nadorino-5456465.jpg
$tahmil->amchan="class.AksidSars1.2.php"; //اسم هذه الصفحة التي تقوم بعملية التحميل
$tahmil->thwara="5"; //عدد الحقول للتحميل
/*
يمكنك اضافة الأنساق التي تريد ان يقوم الزوار بتحميلها
*/
$tahmil->ansaq=array("image/png","image/gif","image/jpg","image/pjpeg","application/x-shockwave-flash");
$tahmil->thwara(); // اظهار الحقول
$tahmil->aksid(); //لتحميل الملفات
<?