Dodano raportowanie błędów w pliku config.php oraz poprawiono formatowanie kodu w pliku upload-product-images.php.

This commit is contained in:
2025-01-06 10:39:18 +01:00
parent 2bddfa31f7
commit a76f349d71
2 changed files with 23 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
define( 'gdir', "/libraries/grid" ); define( 'gdir', "/libraries/grid" );
require_once dirname( __FILE__ ) . '/grid-view.php'; require_once dirname( __FILE__ ) . '/grid-view.php';
require_once dirname( __FILE__ ) . '/gdb.min.php'; require_once dirname( __FILE__ ) . '/gdb.min.php';

View File

@@ -34,14 +34,14 @@ $fileName = isset( $_REQUEST["name"] ) ? $_REQUEST["name"] : '';
$fileName = preg_replace( '/[^\w\._]+/', '-', $fileName ); $fileName = preg_replace( '/[^\w\._]+/', '-', $fileName );
if ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName ) ) if ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName ) )
{ {
$ext = strrpos( $fileName, '.' ); $ext = strrpos( $fileName, '.' );
$fileName_a = substr( $fileName, 0, $ext ); $fileName_a = substr( $fileName, 0, $ext );
$fileName_b = substr( $fileName, $ext ); $fileName_b = substr( $fileName, $ext );
$count = 1; $count = 1;
while ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b ) ) while ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b ) )
$count++; $count++;
@@ -50,9 +50,9 @@ if ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName ) )
$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
if ( $cleanupTargetDir && is_dir( $targetDir ) && ( $dir = opendir( $targetDir ) ) ) if ( $cleanupTargetDir && is_dir( $targetDir ) && ( $dir = opendir( $targetDir ) ) )
{ {
while ( ( $file = readdir( $dir ) ) !== false ) while ( ( $file = readdir( $dir ) ) !== false )
{ {
$tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
@@ -62,7 +62,7 @@ if ( $cleanupTargetDir && is_dir( $targetDir ) && ( $dir = opendir( $targetDir )
} }
closedir($dir); closedir($dir);
} }
else else
die( '{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}' ); die( '{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}' );
@@ -72,40 +72,40 @@ if ( isset( $_SERVER["HTTP_CONTENT_TYPE"] ) )
if ( isset( $_SERVER["CONTENT_TYPE"] ) ) if ( isset( $_SERVER["CONTENT_TYPE"] ) )
$contentType = $_SERVER["CONTENT_TYPE"]; $contentType = $_SERVER["CONTENT_TYPE"];
if ( strpos( $contentType, "multipart" ) !== false ) if ( strpos( $contentType, "multipart" ) !== false )
{ {
if ( isset( $_FILES['file']['tmp_name'] ) && is_uploaded_file( $_FILES['file']['tmp_name'] ) ) if ( isset( $_FILES['file']['tmp_name'] ) && is_uploaded_file( $_FILES['file']['tmp_name'] ) )
{ {
$out = fopen( "{$filePath}.part", $chunk == 0 ? "wb" : "ab" ); $out = fopen( "{$filePath}.part", $chunk == 0 ? "wb" : "ab" );
if ( $out ) if ( $out )
{ {
$in = fopen( $_FILES['file']['tmp_name'], "rb" ); $in = fopen( $_FILES['file']['tmp_name'], "rb" );
if ( $in ) if ( $in )
{ {
while ( $buff = fread( $in, 4096 ) ) while ( $buff = fread( $in, 4096 ) )
fwrite($out, $buff); fwrite($out, $buff);
} }
else else
die( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}' ); die( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}' );
fclose( $in ); fclose( $in );
fclose( $out ); fclose( $out );
@unlink( $_FILES['file']['tmp_name'] ); @unlink( $_FILES['file']['tmp_name'] );
} }
else else
die( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' ); die( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' );
} }
else else
die( '{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}' ); die( '{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}' );
} }
else else
{ {
$out = fopen( "{$filePath}.part", $chunk == 0 ? "wb" : "ab" ); $out = fopen( "{$filePath}.part", $chunk == 0 ? "wb" : "ab" );
if ( $out ) if ( $out )
{ {
$in = fopen( "php://input", "rb" ); $in = fopen( "php://input", "rb" );
if ( $in ) if ( $in )
{ {
while ( $buff = fread( $in, 4096 ) ) while ( $buff = fread( $in, 4096 ) )
fwrite( $out, $buff ); fwrite( $out, $buff );
@@ -115,23 +115,23 @@ else
fclose( $in ); fclose( $in );
fclose( $out ); fclose( $out );
} }
else else
die( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' ); die( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' );
} }
if ( !$chunks || $chunk == $chunks - 1 ) if ( !$chunks || $chunk == $chunks - 1 )
{ {
rename( "{$filePath}.part", $filePath ); rename( "{$filePath}.part", $filePath );
$o = $mdb -> max( 'pp_shop_products_images', 'o' ); $o = $mdb -> max( 'pp_shop_products_images', 'o' );
$mdb -> insert( 'pp_shop_products_images', [ $mdb -> insert( 'pp_shop_products_images', [
'product_id' => $_POST['product_id'] ? $_POST['product_id'] : null, 'product_id' => isset( $_POST['product_id'] ) ? $_POST['product_id'] : null,
'src' => substr( $filePath, 5, strlen( $filePath ) ), 'src' => substr( $filePath, 5, strlen( $filePath ) ),
'o' => ++$o 'o' => ++$o
] ); ] );
$image_id = $mdb -> id(); $image_id = $mdb -> id();
} }