File upload with Non English name

Hi,
I have requirement of uploading filenames with urdu and hindi.
1-Files are getting uploaded and showing properly.
2-but it appear to be strange name on server.

please help me.

<?php 
				 
          $dir="admin_area/documents";
          $results=  scandir($dir);
          foreach ($results as $value) {
             if($value==='.' OR $value==='..')
                continue;
             if(is_file($dir.'/'.$value))
             {
               $size=  ceil(filesize($dir.'/'.$value)/1024);
               
							 echo "<tr><td>$value</td>";
					
					echo '<td><a href="downloads.php?download='.$value.'" class="btn btn-sm btn-primary">download</a>';
						if(isset($_SESSION['username'])){   
               echo '<a href="downloads.php?delete='.rawurlencode($value).'" class="btn btn-sm btn-danger">Delete file</a></td>';
							 } 
                if($size>1000)
                {
                $size=$size/1000;
                   echo "<td>$size mb </td>";   
                }
                else
									{
                   echo "<td>$size kb</td>";
               }
              }
             }
          //for test
						if((isset($_GET['download']))&& basename($_GET['download'])==$_GET['download'])
{ 
	
		$filename=$_GET['download'];
		$path='admin_area/documents/'.$filename;
	
  
   if(file_exists($path))
   {	
		 ob_clean();
		 $file=  fopen($path,'r');
      
      header("Content-Type:application/octet-stream");
      header("Content-Disposition:attachment;filename=".rawurlencode(basename($path)));
      header("Content-Length:".filesize($path));
			
			while(!feof($file))
			{
				$buffer=fread($file,1024);
			
				print $buffer;
			}
     
      exit;
    }
}


if(isset($_GET['delete']))
{
	
   $delete=($_GET['delete']);
   $path="admin_area/documents/".$delete;
   if(file_exists($path))
   {
unlink($path);
header("Location:downloads.php");
     
   }
}

ob_flush();
						 
		
						 
						 ?>

Show us the code you use for the upload processing.

Hi,
I have uploaded the code please have a look on it.

for uploading the files move upload function is usefull for u
(move_uploaded_file($_FILES[“fileToUpload”][“tmp_name”], $target_file)) {
echo "The file “. basename( $_FILES[“fileToUpload”][“name”]). " has been uploaded.”;

@durga
thanks durga for your reply but my file upload is perfect only problem is that uploaded filen containe garbage character in server so my download function is not working …

Does the filesystem of your server support the character set that you need to store the filenames correctly?

If it does, have a look at the iconv function - http://php.net/manual/en/function.iconv.php

This is a screen shot of my server file manager .
Non english filename appears proprerly if I am selectig English UTF-8

So did the iconv() function help at all?

Hi,
I have solved the problem, using rawurlencode().
Thanks for your valuable reply…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.