I have problem with rename file. I need new file name be cyrillic but, when rename img in img folder new name is "Христо Ботев.jpg". That is my code:
$newName = $formdata['name'];
try {
$ext = end(explode('.', $form->img3->getFileName()));
path = (APPLICATION_PATH . '/../public/imgs/' . $newName . '.') . $ext;
$form->img3->addFilter('Rename', array('target' => $path,
'overwrite' => true));
$form->img3->receive();
$form->reset();
}
catch (Exception $e)
{
$editMessage[][] = 'Invalid image.';
}
Try:
$path = (APPLICATION_PATH . '/../public/imgs/' . $newName . '.') . $ext;
$path = iconv('utf-8', 'cp1251', $path);
Try using iconv() function to convert the encoding of the file name.
More info about iconv()
Related
i have problem with file upload. i want to upload file by name or path file in local.
i tried to use
$app->post('/books/cover/{id}', function (Request $request, Response $response, array $args) {
$path = "d:\\1.jpg";
$file = basename($path);
$uploadedFile = $file;
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
$filename = sprintf('%s.%0.8s', $args["id"], $extension);
$directory = $this->get('settings')['upload_directory'];
$uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
return $response->withJson(["status" => "failed", "data" => "0"], 200);
}
});
my cakephp3 plugin with name "AdminTheme" has a localisation file.
AdminTheme
/src
/Locale
/de
AdminTheme.po
The locale change perfectly. In my templates I use the function
__d('AdminTheme', 'Sign In')
The function
\Cake\I18n\MessagesFileLoader::__invoke()
says in line 122 (is_file()): File not found.
pathToMyCake/plugins/AdminTheme/src/Locale/de/AdminTheme.po
public function __invoke()
{
$package = new Package('default');
$folders = $this->translationsFolders();
$ext = $this->_extension;
$file = false;
$fileName = $this->_name;
$pos = strpos($fileName, '/');
if ($pos !== false) {
$fileName = substr($fileName, $pos + 1);
}
foreach ($folders as $folder) {
$path = $folder . $fileName . ".$ext";
if (is_file($path)) {
$file = $path;
break;
}
}
if (!$file) {
return $package;
}
$name = ucfirst($ext);
$class = App::classname($name, 'I18n\Parser', 'FileParser');
if (!$class) {
throw new RuntimeException(sprintf('Could not find class %s', "{$name}FileParser"));
}
$messages = (new $class)->parse($file);
$package->setMessages($messages);
return $package;
}
Why?
The file is correctly?
Please help me. Very thank's.
The debugger screens
I'm confused.
I am trying to fetch files from s3 using Amazon::S3 module in Perl . I am successfully able to download files which are not prefixed but unable to fetch prefixed files like test/abc.txt.
I am using below code.
sub export_bucket {
my ($conn, $bucket, $directory) = #_;
$bucket = $conn->bucket($bucket);
my $response = $bucket->list();
print $response->{bucket}."\n";
for my $key (#{ $response->{keys} }) {
print "\t".$key->{key}."\n";
_export_file($conn,$bucket,$key->{key}, $directory.'/'.$key->{key});
}
}
sub _export_file {
my ($conn,$bucket,$name,$path) = #_;
print "Downloading $name file","\n";
my $test = $bucket->get_key_filename($name,'GET',$path);
print Dumper($test);
my $acl = $bucket->get_acl($name);
print Dumper($acl);
open my $acl_file, '>', $path.'.acl';
print $acl_file $acl;
close $acl_file;
}
Suggest me what changes should i make so that when a prefixed/folder comes i should be able to download the folder as well.
Thanks
You need to modify you code to create the target directory on your local filesystem if it does not already exist. It should look something like this:
use File::Path qw[make_path];
sub export_bucket {
my ( $conn, $bucket, $directory ) = #_;
$bucket = $conn->bucket($bucket);
my $response = $bucket->list();
print $response->{bucket} . "\n";
for my $key ( #{ $response->{keys} } ) {
print "\t" . $key->{key} . "\n";
_export_file( $conn, $bucket, $key->{key}, $directory . '/' . $key->{key} );
}
}
sub _export_file {
my ( $conn, $bucket, $name, $path ) = #_;
print "Downloading $name file", "\n";
my $test = $bucket->get_key_filename( $name, 'GET', $path );
print Dumper($test);
my $acl = $bucket->get_acl($name);
print Dumper($acl);
## get path directory part
my ($dir_part) = $path =~ /(.+)\/[^\/]+$/;
unless ( -d $dir_part ) {
make_path($dir_part);
}
open my $acl_file, '>', $path . '.acl';
print $acl_file $acl;
close $acl_file;
}
Perhaps $directory has a trailing "/" already in the case that is failing (or $key->{key} has a preceding slash)? Try debug-printing $directory and $path in the code to see exactly what your string arguments are.
i have the following code in my zf project :
$index = Zend_Search_Lucene::open(APPLICATION_PATH . '/cache/search_index');
$doc = new Zend_Search_Lucene_Document();
$title = "سلام سینا xxx sad";
$doc->addField(Zend_Search_Lucene_Field::Text('title', $title));
$index->addDocument($doc);
$index->commit();
$index->optimize();
echo "Index contains " . $index->count() . " documents.\n\n";
$results = $index->find('xxx');
foreach ($results as $res) {
var_dump($res->title);
}
when var_dump performs output ->
string(39) "سینا جان xxx sad"
when i user utf_decode
string(25) "س�?ا�? س�?�?ا xxx sad"
how can i decode that correctly ! :(?
i already used the solution in this SOF quesion -> lucene encoding problem in zend framework
but not works and a notice error added about iconv !
plz help :)
Fixed by this code:
$index = Zend_Search_Lucene::open(APPLICATION_PATH . '/cache/search_index');
$doc = new Zend_Search_Lucene_Document();
$title = "سلام سینا xxx sad";
$doc->addField(Zend_Search_Lucene_Field::Text('title', $title,"UTF8"));
$index->addDocument($doc);
$index->commit();
$index->optimize();
echo "Index contains " . $index->count() . " documents.\n\n";
var_dump($index->getDocument(9));
echo "Search";
$results = $index->find('سینا');
foreach ($results as $res) {
var_dump($res->title);
}
die(1);
I'm new to perl but was wondering if anyone know of a script that was similar to the following PHP version which works great!
private function resolve_href ( $base, $href ) {
if (!$href)
return $base;
$rel_parsed = parse_url($href);
if (array_key_exists('scheme', $rel_parsed))
return $href;
$base_parsed = parse_url("$base ");
if (!array_key_exists('path', $base_parsed))
$base_parsed = parse_url("$base/ ");
if ($href{0} === "/")
$path = $href;
else
$path = dirname($base_parsed['path']) . "/$href";
$path = preg_replace('~/\./~', '/', $path);
$parts = array();
foreach ( explode('/', preg_replace('~/+~', '/', $path)) as $part ) {
if ($part === "..")
array_pop($parts);
elseif ($part!="")
$parts[] = $part;
}
$dir = ( ( array_key_exists('scheme', $base_parsed)) ? $base_parsed['scheme'] . '://' . $base_parsed['host'] : "" ) . "/" . implode("/", $parts);
return str_replace( "\/", '', $dir );
}
Any help is much appreciated
See URI:
#!/usr/bin/perl
use strict; use warnings;
use URI;
my $u = URI->new_abs('../foobar', 'http://foo.com/bar/poo/');
print $u->canonical;
Output:
http://foo.com/bar/foobar