Upload & Overwrite

localman

New Member
با سلام :
دوستان میشه بگید چه جوری خاصیت Overwrite رو به این کد اضافه کنم ؟

PHP:
<?php

 echo  '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
 echo  '<input type="file" name="userfile">';
 echo  '<input type="submit" value="upload">';
 echo  '</form>';

$path = './' ;
$max_size = 200000;
if(isset($HTTP_POST_FILES['userfile']))
{
 if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
 {
  if($HTTP_POST_FILES['userfile']['size'] < $max_size)
  {
    if(!file_exists($path . $HTTP_POST_FILES['userfile']['name']))
    {
     if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name']))
     {
      $html_output = 'Upload sucessful!<br>';
      $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>';
      $html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>';
      $html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br>';
      $image = $HTTP_POST_FILES['userfile']['name'] ;
     }else{
      $html_output = 'Upload Failed !<br>';
      if(!is_writeable($path))
      {
       $html_output = 'The Directory "'.$path.'" Must Be Writeable!<br>';
      }else{
       $html_output = 'An Unknown Error Ocurred .<br>';      
      }
     }
    }else{
     $html_output = 'The File Already Exists<br>';
    }
    }
   else{
    $html_output = 'Wrong file type<br>';
   }
  }else{
   $html_output = 'The file is too big<br>';
  }
 }


echo @$html_output;

?>
 

D.A.V.O.O.D

Member
سلام
کدت رو تست نکردم که ببینم کار می کنه یا نه !؟ ولی با تغییراتی که دادم OverWrite فعال شده ...
PHP:
<?php

 echo  '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
 echo  '<input type="file" name="userfile">';
 echo  '<input type="submit" value="upload">';
 echo  '</form>';

$path = './D' ;
$max_size = 200000;
if(isset($HTTP_POST_FILES['userfile']))
{
    if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
    {
        if($HTTP_POST_FILES['userfile']['size'] < $max_size)
        {
            if( file_exists($path . $HTTP_POST_FILES['userfile']['name'] ) )
            {
                @unlink( $path . $HTTP_POST_FILES['userfile']['name'] );
            }
            if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name']))
            {
                $html_output = 'Upload sucessful!<br>';
                $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>';
                $html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>';
                $html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br>';
                $image = $HTTP_POST_FILES['userfile']['name'] ;
            } else
            {
                $html_output = 'Upload Failed !<br>';
                if(!is_writeable($path))
                {
                    $html_output = 'The Directory "'.$path.'" Must Be Writeable!<br>';
                } else
                {
                    $html_output = 'An Unknown Error Ocurred .<br>';      
                }
            }
        } else
        {
            $html_output = 'Wrong file type<br>';
        }
    } else
    {
        $html_output = 'The file is too big<br>';
    }
}


echo @$html_output;
?>

موفق باشی
 

foranyone

Well-Known Member
برا آپلود من همیشه از کلاس استفاده می کنم و به راحتی هم میشه خاصیت های مختلف رو اعمال کرد:paint:
 

جدیدترین ارسال ها

بالا