PDA

View Full Version : سوال: مشکل در آپلود



abbas27
چهارشنبه 27 اسفند 1393, 17:35 عصر
سلام-یکی از دوستان یه کلاس آپلود فایل نوشته(http://barnamenevis.org/showthread.php?488804-%DA%A9%D9%84%D8%A7%D8%B3-%D8%A2%D9%BE%D9%84%D9%88%D8%AF-%D9%81%D8%A7%DB%8C%D9%84-eup-v-1).من ای کلاس رو که استفاده میکنم توی هر مرورگری جواب نمیده.مثلا فایلهای pdf توی موزیلا آپلود نمیشه اما توی ie جواب میده یا فایلهای zip توی ieوموزیلا آپلود میشه اما توی کروم نمیش؟


<?php


class eup {
// Easy Upload Prans :)
private $dir='upload/'; // end = /
private $domin = '127.0.0.1'; // http:// and /
private $random_name = false;
private $max_size = 50000000; //‌ Byte
private $format,$type,$log,$ex;
private $while = 0;
private $method = '';
private $export = '';
public function random_name ($random_name){
$this->random_name = $random_name;
}
public function set_dir ($dir){
if (!is_dir ($dir)){
mkdir ($dir,0775) or die ('مشکلی در ساخت پوشه "'.$dir.'" رخ داد');
}
$this->dir=$dir;
}
public function set_domin ($domin){
$this->domin=$domin;
}
public function set_while ($while){
$this->while=$while;
}
public function max_size ($max_size){
$this->max_size=$max_size;
}
public function valid_format (array $format){
$this->format=$format;
}
public function valid_type (array $type){
$this->type=$type;
}
public function set_log ($method){
$this->method=$method;
}
public function set_export ($method){
$this->export=$method;
}
private function format ($name,$lower=false){
$name = end ( explode ('.',$name));
return ($lower ? strtolower ($name) : $name );
}
private function check_size ($var){
return ($var<=$this->max_size ? true:false);
}
private function check_format ($format){
if ($this->format==null){
die ('لطفا فرمت های مجاز را تعین کنید');
}else{
$new = $this->format;
$new [] = $format;
$new = array_unique ($new);
return ($new==$this->format?true:false);
}
}
private function check_type ($type){
if ($this->type==null){
die ('لطفا MIME های مجاز را تعین کنید');
}else{
$new = $this->type;
$new [] = $type;
$new = array_unique ($new);
return ($new==$this->type?true:false);
}
}
private function get_url (){
return $this->domin.$this->dir;
}
private function file_new_name ($name){
$format = '.'.$this->format ($name);
if ($this->random_name){
return md5 ($name.rand (100000,999999)).$format;
}else{
return str_replace (array ($format,'.'),array ('','_'),$name).$format;
}
}
private function create_unique_name ($name){
$format = '.'.$this->format ($name);
$return = str_replace ($format,'',$name).'-'.date ('Y-m-d_H-i-s').rand (100,999).$format;
if (is_file ($this->dir.$return)){
$this->create_unique_name ($name);
}
return $return;
}

private function add_log ($log){
if ($this->method=='array'){
$this->log[] = $log;
}else{
$this->log .= $log . $this->method;
}
}
private function check_name ($name){
$name = explode ('.',$name);
return (isset ($name ['1'])?true:false);
}
public function log (){
return $this->log;
}
public function export (){
return $this->ex;
}
private function upload_file ($var,$key=''){
if($key!==''){
$var ['error'] = $var ['error'][$key];
$var ['name'] = $var ['name'][$key];
$var ['tmp_name'] = $var ['tmp_name'][$key];
$var ['type'] = $var ['type'][$key];
$var ['size'] = $var ['size'][$key];
}
if ($var ['name']!==''){
if ($var ['error'] <= 0){
if ($this->check_name ($var ['name'])){
if ($this->check_format ($this->format ($var ['name']),true)){
if($this->check_type ($var ['type'])){
if($this->check_size ($var ['size'])){
$var ['old_name'] = $var ['name'];
$var ['name'] = $this->file_new_name ($var ['name']);
if (is_file ($this->dir.$var ['name'])){
$var ['name'] = $this->create_unique_name ($var ['name']);
}
if(move_uploaded_file($var ['tmp_name'],$this->dir.$var ['name'])){
$this->add_log ('فایل "'.$var ['old_name'].'" با موفقیت آپلود شد');
return $this->get_url().$var ['name'];
}else{
$this->add_log ('مشکلی در اجرای عملیات رخ داد (آپلود فایل "'.$var ['old_name'].'")');
}
}else{
$this->add_log ('سایز فایل "'.$var ['name'].'" بیش از اندازه مجاز می باشد');
}
}else{
$this->add_log ('فرمت فایل (MIME) "'.$var ['name'].'" شده مجاز نیست');
}
}else{
$this->add_log ('فرمت فایل "'.$var ['name'].'" شده مجاز نیست');
}
}else{
$this->add_log ('فایل "'.$var ['name'].'" شده مجاز نیست');
}
}else{
$this->add_log ('مشکلی در اجرای عملیات رخ داد (آپلود فایل "'.$var ['name'].'")');
}
}
}
public function upload ($var_name){
if($this->while){
$array = array ();
foreach ($var_name as $key=> $value){
$var [$key] = $value;
}
$num = 0;
$this->while = ($this->while=='auto'?count ($var):$this->while);
while ($num<$this->while){
$temp = $this->upload_file ($var,$num);
if($temp){
if($this->export=='array'){
$export [] = $temp;
}else{
$export .= $temp.$this->export;
}
}
$num++;
}
$this->ex = ($export?$export:false);
}else{
$this->ex = $this->upload_file ($var_name);
}
}
}?>
<?php


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



$upload = new eup;
$upload->set_dir ('prans_upload/'); // نیمه الزامی
$upload->set_domin ('127.0.0.1'); // نیمه الزامی
// $upload->set_log (''); // اختیاری
//$upload->set_export (''); // اختیاری
$upload->set_while ('auto'); // اختیاری
//$upload->random_name (false); // اختیاری
$upload->valid_format (array ('pdf','zip','jpeg','jpg','gif','png')); // الزامی
$upload->valid_type (array ('application/pdf','application/x-zip-compressed','application/zip','multipart/x-zip','application/x-compressed','image/jpeg','image/jpg','image/png','image/gif')); // الزامی
$upload->upload ($_FILES ['prans']); // الزامی
print_r ($upload->export()); // اختیاری
print_r ($upload->log()); // اختیاری
}
?>
<html >
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>


<form method="post" enctype="multipart/form-data">
<input type="file" name="prans[]">
<input type="file" name="prans[]">
<input type="file" name="prans[]">
<input type="file" name="prans[]">
<input type="file" name="prans[]">
<input type="submit" name="ok" value="آپلود !">
</form>
</body>
</html>

vahidqara
چهارشنبه 27 اسفند 1393, 18:14 عصر
دوست خوب اینو تو همون تاپیک مطرح کن ؛ که نویسنده هم مشکله کارشو پی ببره هم بهتر جوابه شما رو میده

abbas27
چهارشنبه 27 اسفند 1393, 20:07 عصر
مشکل رو گفتم ولی ظاهرا واسه خودشون درست کار میکنه و مشکلی نداره.کاش بقیه دوستان هم کد رو تست میکردن که آیا برای اونها هم این مشکل وجود داره؟