Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 946269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:53:19+00:00 2026-05-15T22:53:19+00:00

I am using PHP S3.PHP class to manage files on Amazon S3. I use

  • 0

I am using PHP S3.PHP class to manage files on Amazon S3. I use the copyObject() function to copy files in my S3 bucket. All works great until I meet filenames that need to be urlencoded (I urlencode everything anyway). When a filename ends up with % characters in it the copyObject() function spits the dummy.

for example – the filename 63037_Copy%287%29ofDSC_1337.JPG throws the following error when passed to copyObject() –

Warning:  sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in ..... S3.php on line 477

Here’s the copyObject function line 477

public static function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array()) {
    $rest = new S3Request('PUT', $bucket, $uri);
    $rest->setHeader('Content-Length', 0);
    foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
    foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
    $rest->setAmzHeader('x-amz-acl', $acl);
    $rest->setAmzHeader('x-amz-copy-source', sprintf('/%s/%s', $srcBucket, $srcUri));
    if (sizeof($requestHeaders) > 0 || sizeof($metaHeaders) > 0)
        $rest->setAmzHeader('x-amz-metadata-directive', 'REPLACE');
    $rest = $rest->getResponse();
    if ($rest->error === false && $rest->code !== 200)
        $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
    if ($rest->error !== false) {
-------------------------------------------- LINE 477 ----------------------------


        **trigger_error(sprintf("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s",
        $rest->error['code'], $rest->error['message']), E_USER_WARNING);**


-------------------------------------------- LINE 477 ----------------------------

        return false;
    }
    return isset($rest->body->LastModified, $rest->body->ETag) ? array(
        'time' => strtotime((string)$rest->body->LastModified),
        'hash' => substr((string)$rest->body->ETag, 1, -1)
    ) : false;
}

Has anyone come across this before? There is absolutely no problem when using filenames which don’t change when urlencoded, and Ive already tried removing all whitespace from filenames but wont be able to catch all characters, like brackets which is the problem in the example here. And I dont want to go down that road anyway as I want to keep the filenames as close to the original as possible.

thanks guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:53:19+00:00Added an answer on May 15, 2026 at 10:53 pm

    Redo the line this way:

    trigger_error("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): ". sprintf("[%s] %s",
            $rest->error['code'], $rest->error['message']), E_USER_WARNING);
    

    %’s in the first parameter to sprintf are identified as the placeholders for values. Because your filenames are first inserted in the string and that string is then passed to sprintf(), sprintf() mistakenly interprets the %’s in the file names as placeholders.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am using below third party API in my project development http://undesigned.org.za/2007/10/22/amazon-s3-php-class I have done
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I have send an email using php mailer class. mail was sending successfully but
Language: PHP / Using Class Upload by Colin Verot About: Multiple Uploading The code
I am compressing an image using following class.. <?php class SimpleImage { var $image;
I'm using CakeDC-Users plugin. <?php class Post extends AppModel { public $useTable='posts'; public $belongsTo
I am uploading video on twitvid using its official php library. http://www.martin-gardner.co.uk/twitvid/twitvid.class.example.php#embedvideo But when
i'm using the DOMdocument class in php whenever i want to create a XML
I'm using a Google Analytics API Class in PHP made by Doug Tan to
I'm trying to send mail using phpMailer. It's my code: <?php require_once('phpmailer/class.phpmailer.php'); $mail =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.