php - Problem with sprintf error when using S3->copyObject() and filenames with % in them -


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 until I complete the filenames, do all the good work, which requires urlencoded (I urlencode everything anyway) is. For example - file name 63037_Copy% 287% 29ofDSC_1337.JPG throws the following error when passed to copyObject () when a file name ends with% characters copyObject () function dummy spits

for example - -

  Warning: sprintf () [& lt; A href = 'function.sprintf' & gt; Function.sprintf & lt; / A & gt;]: line 477  

Here is the copyObject function in line 477

  public Fixed function copyObject ($ srcBucket, $ srcUri, $ bucket, $ uri, $ ACL = self :: ACL_PRIVATE, $ metaHeaders = array (), $ requestHeaders = array ()) {$ rest = new S3Request ('PUT', $ Bucket, $ Yuri); $ Remainder- & gt; Set header ('content-length', 0); Foreach ($ requestHeaders $ h = & gt; $ v) $ rest- & gt; Set header ($ h, $ v); Forex Currency ($ metaHeaders $ h = & gt; $ v) $ rest- & gt; SetAmzHeader ('x-amz-meta-'. $ H, $ v); $ Remainder- & gt; SetAmaz header ('X-AMS-ACL', $ ACL); $ Remainder- & gt; SetAmaz header ('x-amaz-copy-source', sprintoff ('/% s /% s', $ src bucket, $ srcUri)); If (; 0+ sizeof ($ metaHeaders) & gt; sizeof ($ requestHeaders) & gt0) $ left & gt; SetAmzHeader ('X-AMZ-Metadata-Instructions', 'REPLACE'); $ Balance = $ rest- & gt; Millerspons (); If ($ rest-> error === incorrect & amp; $ rest-> code! == 200) $ rest-> error = array ('code' = & gt; $ rest- & gt; code, ' Message '= & gt;' unexpected HTTP status'); If ($ remainder-> error! == incorrect) {----------------------------------- - -------- Line 477 ---------------------------- ** Trigger_rerer (sprintoff ("S3 :: Copy object ({$ srcBucket} {$ srcUri} {$ bucket} {$ uri}): [% s]% s ", $ rest & gt; error ['code'], $ rest & gt; error ['message ']), E_USER_WARNING); ** ----------------------------------------- Line 477 - -------------------------- return false; } Return issue ($ rest-> body-> last modified, $ remainder-> body-> ETag)? Array ('time' = & gt; strtotime (string) $ left & gt; body & gt; LastModified), 'hash' => substr (string) $ balance & gt; body & gt; ETag, 1 , - 1)): Wrong; }  

Has anybody come on this before? There is no problem while using the file names when the URL is linked, and Ive was previously trying to extract all the white space with the filenames but not able to capture all the characters, such as parentheses, in that example There is a problem and I would not like to go down that path because I want to keep the filenames as close to the original as possible.

Thanks guys

Redo the line like this:

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

% are identified as a placeholder for the value in the first parameter of sprintf. Because your file names are first entered in the string and this string is then passed to sprintf (), sprintf () incorrectly interprets file names as placeholders of%.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -