We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Simple S3 Upload Extension now on EE2 (current version: 1.2.1)

Development and Programming

Andrew Macpherson's avatar
Andrew Macpherson
38 posts
15 years ago
Andrew Macpherson's avatar Andrew Macpherson

Thank you! And k-ching! Just purchased the add-on.

Only one little thing, though: I’m getting the following error when I try to set up a new field:

An Error Was Encountered curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

I’ve checked PHP info on the server, and CURL support is enabled … It also says that safe_mode is off

Unfortunately, though, the open_basedir does indeed have a “local value” (but not a “master value”)

Any idea what I should be doing now? I assume the service provider (EngineHosting) must have set the local value. Is it something that I should be asking them about? I have no idea what open_basedir does …

Thanks in advance for any advice you may be able to give Andrew

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

Basically open_basedir prevents PHP from changing to a directory outside of the one it has been assigned, restricting it to a virtual fenced in area. Because cURL is not strictly a part of PHP and cannot access the open_basedir settings, and because CURLOPT_FOLLOWLOCATION could follow redirects outside of the fenced area, it has been made to throw an error in the newer versions of PHP. I know that this extension has worked on EngineHosting in the past, so it’s possible that they recently upgraded to a new version of PHP.

You should be able to comment that line out and be fine as I don’t believe S3 will issue any redirects for the requests this extension sends.

For EE1, comment out line 2194 in ft.simple_s3_uploader.php For EE2, comment out line 1256 in libraries/S3.php

in both cases the line to comment out looks like this:

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

Let me know if that works for you. -Ty

       
Massbehavior's avatar
Massbehavior
6 posts
15 years ago
Massbehavior's avatar Massbehavior

This is on a clean install in EE2 I keep getting this error:

S3::listBuckets(): [60] SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Any thoughts?

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

sounds like your OpenSSL/cURL certificates aren’t set up properly on the server. might want to ask whoever manages your server about that. if you google for that error you can read some information about it.

In the meantime, you should be able to avoid the error by disabling SSL.

On line 44 of libraries/S3.php you should be able to change:

public static $useSSL = true;

to

public static $useSSL = false;

hopefully that will solve this for you.

       
Andrew Macpherson's avatar
Andrew Macpherson
38 posts
15 years ago
Andrew Macpherson's avatar Andrew Macpherson
Basically open_basedir prevents PHP from changing to a directory outside of the one it has been assigned, restricting it to a virtual fenced in area. Because cURL is not strictly a part of PHP and cannot access the open_basedir settings, and because CURLOPT_FOLLOWLOCATION could follow redirects outside of the fenced area, it has been made to throw an error in the newer versions of PHP. I know that this extension has worked on EngineHosting in the past, so it’s possible that they recently upgraded to a new version of PHP. You should be able to comment that line out and be fine as I don’t believe S3 will issue any redirects for the requests this extension sends. For EE1, comment out line 2194 in ft.simple_s3_uploader.php For EE2, comment out line 1256 in libraries/S3.php in both cases the line to comment out looks like this:
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
Let me know if that works for you. -Ty

Thanks, that seems to have done the trick!

Cheers Andrew

       
Andrew Macpherson's avatar
Andrew Macpherson
38 posts
15 years ago
Andrew Macpherson's avatar Andrew Macpherson

Hello again. Just one more little question:

I notice that the files I have been uploaded are being renamed (using numbers). Is there any way to change that behaviour, so that they keep the original file name?

Regards Andrew Macpherson Sydney, Australia

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

look for the following lines in the ft.simple_s3_uploader.php file (they’ll be near the top of the _upload_to_s3() method:

$aws_object  = preg_replace("/[^a-z0-9.]+/i", "-", time() . "-" . $pathinfo['filename'] . "." . $pathinfo['extension']);
$aws_thumb   = preg_replace("/[^a-z0-9.]+/i", "-", time() . "-" . $pathinfo['filename'] . "-thumb." . $pathinfo['extension']);

you can remove the time() part of the expression if you need to alter this behavior.

You may have your reasons for doing this, but note that the original filename is still available to you via the {my_custom_field:name} template tag. All template tags can be found here. If multiple people are going to be uploading files, the timestamps ensure that nobody overwrites anyone else’s stuff.

       
Andrew Macpherson's avatar
Andrew Macpherson
38 posts
15 years ago
Andrew Macpherson's avatar Andrew Macpherson

Thanks, Ty, I really appreciate your quick replies to my questions!

One of the reasons we need to preserve the filename is that we have a few PDF and Word documents that people need to download as part of a specialised workflow, and it is important that each file retains the original name. If the only things we were uploading were images for display, the renaming wouldn’t be an issue, and with images and certain other files I can certainly see the value in the timestamp, as you point out.

Looking at your code, though, raises one further little question: I’m not a PHP guy, so I’ve probably got it completely wrong, but the two lines you’ve highlighted make me think that the the timestamp should be added at the start of the filename. So “file.pdf” would become something like “1234567890-file.pdf”. If so, I must be doing something wrong, because the file that ends up on S3 is actually “1234567890-.pdf” (that is, just the timestamp plus a dash). All references to the original filename are being removed, though the correct name is still being returned by the {custom_field:name} tag, though.

A good compromise for us, in fact, might be an option to append the timestamp at the end of the filename, which would solve both issues. In other words, we would be happy enough if “file.pdf” became “file-1234567890.pdf”. That would keep the filename for the workflow, avoid the issue of the file being overwritten, and have the added bonus that the timestamp might also come in handy for tracking what version of a file people had been using (some of the files will be returned to us as part of the workflow).

Anyway, I might have a bit of a play to see what we can come up with … hopefully without breaking the whole thing! 😉

If you don’t mind taking feature requests, though, do you think there’s any chance that file naming conventions could be introduced as a field setting? If that was possible, and not too much extra work, I think it would certainly take care of our own particular issue, and maybe even avoid any other potential concerns that others might have in the future.

Whatever happens, though, thanks heaps for all your help with this!

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

that is one feature I’ve had on my list of thoughts for some time now. I’m not sure when I’ll be able to implement it though.

       
Andrew Macpherson's avatar
Andrew Macpherson
38 posts
15 years ago
Andrew Macpherson's avatar Andrew Macpherson

As long as it’s on your list of thoughts, I’m happy … because you make me very confident that it will indeed come one day! 😊

Seriously, though, I really do appreciate the time you put into developing your product, and the speed with which you manage it (it’s if’s a relatively simple fix, of course). I have had experiences wher other products sometimes put things waaaay down on their feature list, even if it might only take a short time (like, for example, when you added the custom headers fix).

So thanks heaps Andrew Macpherson Sydney, Australia

       
Andrew Macpherson's avatar
Andrew Macpherson
38 posts
15 years ago
Andrew Macpherson's avatar Andrew Macpherson
look for the following lines in the ft.simple_s3_uploader.php file (they’ll be near the top of the _upload_to_s3() method:
$aws_object  = preg_replace("/[^a-z0-9.]+/i", "-", time() . "-" . $pathinfo['filename'] . "." . $pathinfo['extension']);
$aws_thumb   = preg_replace("/[^a-z0-9.]+/i", "-", time() . "-" . $pathinfo['filename'] . "-thumb." . $pathinfo['extension']);
you can remove the time() part of the expression if you need to alter this behavior. You may have your reasons for doing this, but note that the original filename is still available to you via the {my_custom_field:name} template tag. All template tags can be found here. If multiple people are going to be uploading files, the timestamps ensure that nobody overwrites anyone else’s stuff.

You’ll have to forgive me, but I can’t seem to get things the way I want them. Nothing I’ve tried so far has given me just the filename. There must be something I’m doing wrong, but I can’t figure it out. If you ever do get a bit of time, I’d really appreciate it if you could double-check what I really do need to do.

As I mentioned before, the original version doesn’t give me any trace of the filename when uploaded to S3. It just gives the timestamp … so removing the timestamp bit just leaves a blank file, or a “-thumb.jpg”.

Cheers Andrew

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

it appears that the pathinfo() PHP function on EngineHosting doesn’t work quite like it does everywhere else I’ve tested. Perhaps they’re running an older version of PHP 5. After digging through the docs, it appears that the filename option was added to the pathinfo function in 5.2.

I’ve modified the extension and will send you a copy via PM for you to test, Andrew. Please let me know if it solves the filename issue on EngineHosting as I don’t have access to a server running an older version of PHP at the moment.

       
1 2 3

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.