Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Use of undefined constant - fix #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions backend-php/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
$config = [

/* base url for image folders */
BASE_URL => ( array_key_exists( "HTTPS", $_SERVER ) ? "https://" : "http://" ) . $_SERVER[ "HTTP_HOST" ] . dirname( dirname( $_SERVER[ "PHP_SELF" ] ) ) . "/",
'BASE_URL' => ( array_key_exists( "HTTPS", $_SERVER ) ? "https://" : "http://" ) . $_SERVER[ "HTTP_HOST" ] . dirname( dirname( $_SERVER[ "PHP_SELF" ] ) ) . "/",

/* local file system base path to where image directories are located */
BASE_DIR => dirname( dirname( $_SERVER[ "SCRIPT_FILENAME" ] ) ) . "/",
'BASE_DIR' => dirname( dirname( $_SERVER[ "SCRIPT_FILENAME" ] ) ) . "/",

/* url to the uploads folder (relative to BASE_URL) */
UPLOADS_URL => "uploads/",
'UPLOADS_URL' => "uploads/",

/* local file system path to the uploads folder (relative to BASE_DIR) */
UPLOADS_DIR => "uploads/",
'UPLOADS_DIR' => "uploads/",

/* url to the static images folder (relative to BASE_URL) */
STATIC_URL => "uploads/static/",
'STATIC_URL' => "uploads/static/",

/* local file system path to the static images folder (relative to BASE_DIR) */
STATIC_DIR => "uploads/static/",
'STATIC_DIR' => "uploads/static/",

/* url to the thumbnail images folder (relative to BASE_URL */
THUMBNAILS_URL => "uploads/thumbnails/",
'THUMBNAILS_URL' => "uploads/thumbnails/",

/* local file system path to the thumbnail images folder (relative to BASE_DIR) */
THUMBNAILS_DIR => "uploads/thumbnails/",
'THUMBNAILS_DIR' => "uploads/thumbnails/",

/* width and height of generated thumbnails */
THUMBNAIL_WIDTH => 90,
THUMBNAIL_HEIGHT => 90
'THUMBNAIL_WIDTH' => 90,
'THUMBNAIL_HEIGHT' => 90
];
30 changes: 15 additions & 15 deletions backend-php/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,25 @@ function ProcessUploadRequest()

if ( $_SERVER[ "REQUEST_METHOD" ] == "GET" )
{
$dir = scandir( $config[ BASE_DIR ] . $config[ UPLOADS_DIR ] );
$dir = scandir( $config[ 'BASE_DIR' ] . $config[ 'UPLOADS_DIR' ] );

foreach ( $dir as $file_name )
{
$file_path = $config[ BASE_DIR ] . $config[ UPLOADS_DIR ] . $file_name;
$file_path = $config[ 'BASE_DIR' ] . $config[ 'UPLOADS_DIR' ] . $file_name;

if ( is_file( $file_path ) )
{
$size = filesize( $file_path );

$file = [
"name" => $file_name,
"url" => $config[ BASE_URL ] . $config[ UPLOADS_URL ] . $file_name,
"url" => $config[ 'BASE_URL' ] . $config[ 'UPLOADS_URL' ] . $file_name,
"size" => $size
];

if ( file_exists( $config[ BASE_DIR ] . $config[ THUMBNAILS_DIR ] . $file_name ) )
if ( file_exists( $config[ 'BASE_DIR' ] . $config[ 'THUMBNAILS_DIR' ] . $file_name ) )
{
$file[ "thumbnailUrl" ] = $config[ BASE_URL ] . $config[ THUMBNAILS_URL ] . $file_name;
$file[ "thumbnailUrl" ] = $config[ 'BASE_URL' ] . $config[ 'THUMBNAILS_URL' ] . $file_name;
}

$files[] = $file;
Expand All @@ -103,23 +103,23 @@ function ProcessUploadRequest()

$file_name = $_FILES[ "files" ][ "name" ][ $key ];

$file_path = $config[ BASE_DIR ] . $config[ UPLOADS_DIR ] . $file_name;
$file_path = $config[ 'BASE_DIR' ] . $config[ 'UPLOADS_DIR' ] . $file_name;

if ( move_uploaded_file( $tmp_name, $file_path ) === TRUE )
{
$size = filesize( $file_path );

$image = new Imagick( $file_path );

$image->resizeImage( $config[ THUMBNAIL_WIDTH ], $config[ THUMBNAIL_HEIGHT ], Imagick::FILTER_LANCZOS, 1.0, TRUE );
$image->writeImage( $config[ BASE_DIR ] . $config[ THUMBNAILS_DIR ] . $file_name );
$image->resizeImage( $config[ 'THUMBNAIL_WIDTH' ], $config[ 'THUMBNAIL_HEIGHT' ], Imagick::FILTER_LANCZOS, 1.0, TRUE );
$image->writeImage( $config[ 'BASE_DIR' ] . $config[ 'THUMBNAILS_DIR' ] . $file_name );
$image->destroy();

$file = array(
"name" => $file_name,
"url" => $config[ BASE_URL ] . $config[ UPLOADS_URL ] . $file_name,
"url" => $config[ 'BASE_URL' ] . $config[ 'UPLOADS_URL' ] . $file_name,
"size" => $size,
"thumbnailUrl" => $config[ BASE_URL ] . $config[ THUMBNAILS_URL ] . $file_name
"thumbnailUrl" => $config[ 'BASE_URL' ] . $config[ 'THUMBNAILS_URL' ] . $file_name
);

$files[] = $file;
Expand Down Expand Up @@ -255,7 +255,7 @@ function ProcessDlRequest()

/* run this puppy through premailer */

$premailer = Premailer::html( $_POST[ "html" ], true, "hpricot", $config[ BASE_URL ] );
$premailer = Premailer::html( $_POST[ "html" ], true, "hpricot", $config[ 'BASE_URL' ] );

$html = $premailer[ "html" ];

Expand All @@ -274,7 +274,7 @@ function ProcessDlRequest()
if ( preg_match( '#/img\?src=(.*)&method=(.*)&params=(.*)#i', $matches[ 1 ][ $i ], $src_matches ) !== FALSE )
{
$file_name = urldecode( $src_matches[ 1 ] );
$file_name = substr( $file_name, strlen( $config[ BASE_URL ] . $config[ UPLOADS_URL ] ) );
$file_name = substr( $file_name, strlen( $config[ 'BASE_URL' ] . $config[ 'UPLOADS_URL' ] ) );

$method = urldecode( $src_matches[ 2 ] );

Expand All @@ -285,11 +285,11 @@ function ProcessDlRequest()

$static_file_name = $method . "_" . $width . "x" . $height . "_" . $file_name;

$html = str_ireplace( $matches[ 1 ][ $i ], $config[ BASE_URL ] . $config[ STATIC_URL ] . urlencode( $static_file_name ), $html );
$html = str_ireplace( $matches[ 1 ][ $i ], $config[ 'BASE_URL' ] . $config[ 'STATIC_URL' ] . urlencode( $static_file_name ), $html );

$image = ResizeImage( $file_name, $method, $width, $height );

$image->writeImage( $config[ BASE_DIR ] . $config[ STATIC_DIR ] . $static_file_name );
$image->writeImage( $config[ 'BASE_DIR' ] . $config[ 'STATIC_DIR' ] . $static_file_name );
}
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ function ResizeImage( $file_name, $method, $width, $height )
{
global $config;

$image = new Imagick( $config[ BASE_DIR ] . $config[ UPLOADS_DIR ] . $file_name );
$image = new Imagick( $config[ 'BASE_DIR' ] . $config[ 'UPLOADS_DIR' ] . $file_name );

if ( $method == "resize" )
{
Expand Down