Dodano raportowanie błędów w pliku config.php oraz poprawiono formatowanie kodu w pliku upload-product-images.php.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
|
||||
define( 'gdir', "/libraries/grid" );
|
||||
require_once dirname( __FILE__ ) . '/grid-view.php';
|
||||
require_once dirname( __FILE__ ) . '/gdb.min.php';
|
||||
|
||||
@@ -34,14 +34,14 @@ $fileName = isset( $_REQUEST["name"] ) ? $_REQUEST["name"] : '';
|
||||
|
||||
$fileName = preg_replace( '/[^\w\._]+/', '-', $fileName );
|
||||
|
||||
if ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName ) )
|
||||
if ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName ) )
|
||||
{
|
||||
$ext = strrpos( $fileName, '.' );
|
||||
$fileName_a = substr( $fileName, 0, $ext );
|
||||
$fileName_b = substr( $fileName, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
|
||||
while ( file_exists( $targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
@@ -50,9 +50,9 @@ if ( file_exists( $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;
|
||||
|
||||
@@ -62,7 +62,7 @@ if ( $cleanupTargetDir && is_dir( $targetDir ) && ( $dir = opendir( $targetDir )
|
||||
}
|
||||
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
||||
else
|
||||
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"] ) )
|
||||
$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" );
|
||||
if ( $out )
|
||||
if ( $out )
|
||||
{
|
||||
$in = fopen( $_FILES['file']['tmp_name'], "rb" );
|
||||
|
||||
if ( $in )
|
||||
if ( $in )
|
||||
{
|
||||
while ( $buff = fread( $in, 4096 ) )
|
||||
fwrite($out, $buff);
|
||||
}
|
||||
}
|
||||
else
|
||||
die( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}' );
|
||||
fclose( $in );
|
||||
fclose( $out );
|
||||
@unlink( $_FILES['file']['tmp_name'] );
|
||||
}
|
||||
}
|
||||
else
|
||||
die( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' );
|
||||
}
|
||||
}
|
||||
else
|
||||
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" );
|
||||
if ( $out )
|
||||
{
|
||||
$in = fopen( "php://input", "rb" );
|
||||
|
||||
if ( $in )
|
||||
if ( $in )
|
||||
{
|
||||
while ( $buff = fread( $in, 4096 ) )
|
||||
fwrite( $out, $buff );
|
||||
@@ -115,23 +115,23 @@ else
|
||||
|
||||
fclose( $in );
|
||||
fclose( $out );
|
||||
}
|
||||
}
|
||||
else
|
||||
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 );
|
||||
|
||||
|
||||
$o = $mdb -> max( 'pp_shop_products_images', 'o' );
|
||||
|
||||
$mdb -> insert( 'pp_shop_products_images', [
|
||||
'product_id' => $_POST['product_id'] ? $_POST['product_id'] : null,
|
||||
|
||||
$mdb -> insert( 'pp_shop_products_images', [
|
||||
'product_id' => isset( $_POST['product_id'] ) ? $_POST['product_id'] : null,
|
||||
'src' => substr( $filePath, 5, strlen( $filePath ) ),
|
||||
'o' => ++$o
|
||||
] );
|
||||
|
||||
|
||||
$image_id = $mdb -> id();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user