mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-12 19:13:57 +02:00
made encoding check only, when function exists
This commit is contained in:
@@ -1810,14 +1810,17 @@ function IFM( params ) {
|
|||||||
// gets the content of a file
|
// gets the content of a file
|
||||||
// notice: if the content is not JSON encodable it returns an error
|
// notice: if the content is not JSON encodable it returns an error
|
||||||
private function getContent( array $d ) {
|
private function getContent( array $d ) {
|
||||||
if( $this->config['edit'] != 1 ) echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
|
if( $this->config['edit'] != 1 )
|
||||||
|
echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
|
||||||
else {
|
else {
|
||||||
$this->chDirIfNecessary( $d['dir'] );
|
$this->chDirIfNecessary( $d['dir'] );
|
||||||
if( file_exists( $d['filename'] ) ) {
|
if( file_exists( $d['filename'] ) && is_readable( $d['filename'] ) ) {
|
||||||
$content = @file_get_contents( $d['filename'] );
|
$content = @file_get_contents( $d['filename'] );
|
||||||
$utf8content = mb_convert_encoding( $content, 'UTF-8', mb_detect_encoding( $content, 'UTF-8, ISO-8859-1', true ) );
|
file_put_contents( "debugifm.txt", "content: ".$content."\n\n\n" );
|
||||||
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $utf8content ) ) );
|
if( function_exists( "mb_check_encoding" ) && ! mb_check_encoding( $content, "UTF-8" ) )
|
||||||
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found" ) );
|
$content = utf8_encode( $content );
|
||||||
|
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $content ) ) );
|
||||||
|
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found or not readable." ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
ifm.php
13
ifm.php
@@ -1810,14 +1810,17 @@ function IFM( params ) {
|
|||||||
// gets the content of a file
|
// gets the content of a file
|
||||||
// notice: if the content is not JSON encodable it returns an error
|
// notice: if the content is not JSON encodable it returns an error
|
||||||
private function getContent( array $d ) {
|
private function getContent( array $d ) {
|
||||||
if( $this->config['edit'] != 1 ) echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
|
if( $this->config['edit'] != 1 )
|
||||||
|
echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
|
||||||
else {
|
else {
|
||||||
$this->chDirIfNecessary( $d['dir'] );
|
$this->chDirIfNecessary( $d['dir'] );
|
||||||
if( file_exists( $d['filename'] ) ) {
|
if( file_exists( $d['filename'] ) && is_readable( $d['filename'] ) ) {
|
||||||
$content = @file_get_contents( $d['filename'] );
|
$content = @file_get_contents( $d['filename'] );
|
||||||
$utf8content = mb_convert_encoding( $content, 'UTF-8', mb_detect_encoding( $content, 'UTF-8, ISO-8859-1', true ) );
|
file_put_contents( "debugifm.txt", "content: ".$content."\n\n\n" );
|
||||||
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $utf8content ) ) );
|
if( function_exists( "mb_check_encoding" ) && ! mb_check_encoding( $content, "UTF-8" ) )
|
||||||
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found" ) );
|
$content = utf8_encode( $content );
|
||||||
|
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $content ) ) );
|
||||||
|
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found or not readable." ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/main.php
13
src/main.php
@@ -363,14 +363,17 @@ class IFM {
|
|||||||
// gets the content of a file
|
// gets the content of a file
|
||||||
// notice: if the content is not JSON encodable it returns an error
|
// notice: if the content is not JSON encodable it returns an error
|
||||||
private function getContent( array $d ) {
|
private function getContent( array $d ) {
|
||||||
if( $this->config['edit'] != 1 ) echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
|
if( $this->config['edit'] != 1 )
|
||||||
|
echo json_encode( array( "status" => "ERROR", "message" => "You are not allowed to edit files." ) );
|
||||||
else {
|
else {
|
||||||
$this->chDirIfNecessary( $d['dir'] );
|
$this->chDirIfNecessary( $d['dir'] );
|
||||||
if( file_exists( $d['filename'] ) ) {
|
if( file_exists( $d['filename'] ) && is_readable( $d['filename'] ) ) {
|
||||||
$content = @file_get_contents( $d['filename'] );
|
$content = @file_get_contents( $d['filename'] );
|
||||||
$utf8content = mb_convert_encoding( $content, 'UTF-8', mb_detect_encoding( $content, 'UTF-8, ISO-8859-1', true ) );
|
file_put_contents( "debugifm.txt", "content: ".$content."\n\n\n" );
|
||||||
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $utf8content ) ) );
|
if( function_exists( "mb_check_encoding" ) && ! mb_check_encoding( $content, "UTF-8" ) )
|
||||||
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found" ) );
|
$content = utf8_encode( $content );
|
||||||
|
echo json_encode( array( "status" => "OK", "data" => array( "filename" => $d['filename'], "content" => $content ) ) );
|
||||||
|
} else echo json_encode( array( "status" => "ERROR", "message" => "File not found or not readable." ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user