<?php
include('header.php');
if($xg20 != 1){
echo $h;
echo $LANGAUGE_CP[626];
echo $f;
exit;
}
echo $h;

$sql = "SELECT * FROM opitions where id=1";
$result = mysql_query ($sql) or die ("Query failed");
$p_cats=mysql_fetch_array($result);
$folderss = $p_cats['name_script'];
$urlsssss = $p_cats['name_path'];
$uploadDir = "../$folderss/";
$count = "10";

$action = $_GET['action'];
if(!isset($action)) $action = "upload";
if($action=="upload"){

if(isset($_GET['pfolder']) AND $_GET['pfolder'] != ""){
$rd = $_GET['pfolder'];
}else{
$rd = $uploadDir;
}

if(isset($_GET['num']) AND $_GET['num'] != 0){
$number = intval($_GET['num']);
}else{
$number = 5;
}
?>
<form name="vbform" method="GET" action="">
<input name="action" type="hidden" value="upload" />
<div align="center"><?php echo $LANGAUGE_CP[397]; ?> <input name="num" value="<?php echo $number; ?>" type="text" size="10" /> <?php echo $LANGAUGE_CP[547]; ?> <input dir="ltr" title="مسار المجلد الذي سيتم تحميل الملفات بداخله" name="pfolder" value="<?php echo $rd; ?>" type="text" size="30" /> <input type="submit" value=" تحديث " /></div>
</form>
<br /><br />
<?php
//if(isset($_GET['pfolder']) AND $_GET['pfolder']!=""){

if(file_exists($rd)){

echo "<form method='POST' action='upload.php?action=uploadimages' enctype='multipart/form-data'>
<input name='number' type='hidden' value='$number' />
<input name='pfolder' type='hidden' value='".$rd."' />
<div align='center'>";
for($i=0;$i<$number;$i++){
echo "".$LANGAUGE_CP[548]." $i : <input size='50' name='userfile[]' type='file' /><br />";
}
echo "<br /><input type='submit' value=' ".$LANGAUGE_CP[549]." ' name='B1' />";
echo "</div></form>";
}else{
echo "<div style='width:60%; margin:0 auto; padding:5px; color:red; text-align:center;'>".$LANGAUGE_CP[550]." <b>".$_GET['pfolder']."</b></div>";
}


//}else{
//echo "<div align='center' class='xtr'>".$LANGAUGE_CP[551]."</div>";
//}



}elseif($action=="uploadimages"){

for($i=0;$i<$count;$i++){
$fileName = $_FILES['userfile']['name'][$i];
$tmpName  = $_FILES['userfile']['tmp_name'][$i];
$fileSize = $_FILES['userfile']['size'][$i];
$fileType = $_FILES['userfile']['type'][$i];


if(!empty($fileName)){
$time = time();
$ext = substr(strrchr($fileName, "."), 1);
$randName = md5(rand() * time());
$randName = substr($randName, 0, 5);
$filePath = $uploadDir . $time . '-' . $randName . '.' . $ext;
$nameindatabase = $time . '-' . $randName . '.' . $ext;
$pathimages = "$folderss/$nameindatabase";

//if($ext == "gif" or $ext == "GIF" or $ext == "jpg" or $ext == "jpeg" or $ext == "png"){

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo $LANGAUGE_CP[552];
exit;
}

echo "".$LANGAUGE_CP[548]." $i : <input name='Name$i' type='text' value='$urlsssss/$pathimages' size='70' dir='ltr' /><br />";
//}else{
//echo "".$LANGAUGE_CP[553]." $i<br />";
//}
}
}


}
echo $f;
?>