I want to create a web form which will allow the user to upload text/rtf files in UTF-8 having foreign language content using PHP and then execute a series of commands on it via the exec() function. After this processing I would be giving it back to the user as a download.
I made rudimentary form in html with a file input form and submit button. and the PHP side has the following contents.
$base_dir = './uploads';
$cmd = "mkdir -p ".$base_dir.' ; mv -v '.$_FILES['file']['tmp_name'].'$_/'.$_FILES['file']['name'].' ; /var/www/cgi-bin/test.awk'.'/var/www/html/uploads/'.$_FILES['file']['name'].'>'.'/var/www/html/uploads/'.$_FILES['file']['name'];
exec($cmd);
print '<a href="http://oceanfizz.usc.edu/uploads/'.$_FILES['file']['name'].'">download file </a>';
But the problem is that the uploaded rtf files seem to have text changes mainly like
so “é became \’8e abd so forth.
I think it is a problem with the encoding
Can someone suggest a fast and easy way to upload files to a server and get back processed files via the browser at the same time preserving the encoding and contents.
Moving files with unix internal move command isnt realy clever. Use instead the php upload function.
To your encoding problem you could first serialize the content of the uploaded file with serialize(); and if the user requests it unserialize it. This is the best way to transport files along the internet.