output details on failure of pwg.images.php: ws_images_upload #962

Open
opened 2026-10-05 00:25:47 +02:00 by adam · 0 comments
Owner

in ws_images_addSimple the $_FILES['image']['error'] is nicely interpreted and converted into a useful message. In ws_images_upload I request to have something similar. Maybe

  if (isset($_FILES['file']['error']) && $_FILES['file']['error'] != 0)
  {
    switch($_FILES['file']['error'])
    {
      case UPLOAD_ERR_INI_SIZE:
        $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
        break;
      case UPLOAD_ERR_FORM_SIZE:
        $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
        break;
      case UPLOAD_ERR_PARTIAL:
        $message = 'The uploaded file was only partially uploaded.';
        break;
      case UPLOAD_ERR_NO_FILE:
        $message = 'No file was uploaded.';
        break;
      case UPLOAD_ERR_NO_TMP_DIR:
        $message = 'Missing a temporary folder.';
        break;
      case UPLOAD_ERR_CANT_WRITE:
        $message = 'Failed to write file to disk.';
        break;
      case UPLOAD_ERR_EXTENSION:
        $message = 'A PHP extension stopped the file upload. ' .
        'PHP does not provide a way to ascertain which extension caused the file ' .
        'upload to stop; examining the list of loaded extensions with phpinfo() may help.';
        break;
      default:
        $message = "Error number {$_FILES['file']['error']} occurred while uploading a file.";
    }
    die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "' . $message . '"}, "id" : "id"}');
  }

to have a helpful output in the JSON WS interface.

in ws_images_addSimple the $_FILES['image']['error'] is nicely interpreted and converted into a useful message. In ws_images_upload I request to have something similar. Maybe ``` if (isset($_FILES['file']['error']) && $_FILES['file']['error'] != 0) { switch($_FILES['file']['error']) { case UPLOAD_ERR_INI_SIZE: $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; break; case UPLOAD_ERR_FORM_SIZE: $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; break; case UPLOAD_ERR_PARTIAL: $message = 'The uploaded file was only partially uploaded.'; break; case UPLOAD_ERR_NO_FILE: $message = 'No file was uploaded.'; break; case UPLOAD_ERR_NO_TMP_DIR: $message = 'Missing a temporary folder.'; break; case UPLOAD_ERR_CANT_WRITE: $message = 'Failed to write file to disk.'; break; case UPLOAD_ERR_EXTENSION: $message = 'A PHP extension stopped the file upload. ' . 'PHP does not provide a way to ascertain which extension caused the file ' . 'upload to stop; examining the list of loaded extensions with phpinfo() may help.'; break; default: $message = "Error number {$_FILES['file']['error']} occurred while uploading a file."; } die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "' . $message . '"}, "id" : "id"}'); } ``` to have a helpful output in the JSON WS interface. <!-- github-sync-id:509510414 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#962