Stichoza / google-translate-php

🔤 Free Google Translate API PHP Package. Translates totally free of charge.
MIT License
1.82k stars 382 forks source link

Warning: open_basedir restriction in effect #7

Closed Tropaion closed 10 years ago

Tropaion commented 10 years ago

Hello, I have tried this:

include ('GoogleTranslate.php');
$tr = new GoogleTranslate("en", "de");
echo $tr->translate("Hello World!");

And I got two Errors and the translated text:

Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/home/.sites/117/site3029/web:/home/.sites/117/site3029/tmp:/usr/share/pear) in /home/.sites/117/site3029/web/GoogleTranslate.php on line 87
Warning: unlink() [function.unlink]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/.sites/117/site3029/web:/home/.sites/117/site3029/tmp:/usr/share/pear) in /home/.sites/117/site3029/web/GoogleTranslate.php on line 95
Hallo Welt !

Can you tell me what is my mistake?

Stichoza commented 10 years ago

Try to change your /tmp folder permissions to 0755 or 0777.

Can you please provide information about server and software (apache, etc.) versons?

Tropaion commented 10 years ago

Here you can see some Infos http://www.yakuzasubs.at/phpinfo.php I dont know Apache Version, but I had PHP5.3 and now I changed to PHP5.5. I dont have access with my ftp Account to the tmp Folder, but I think the permissions are already 0777, because I can upload files in this directory. You can try this here: http://www.yakuzasubs.at/test.php The code of this site is:

<form action="test.php" method="post" enctype="multipart/form-data"> 
<input type="file" name="datei"><br>
<input type="submit" value="Hochladen"> 
</form>
$type = $_FILES['datei']['type'];
echo $type;
$size = $_FILES['datei']['size'];
echo $size;
$dir = $_FILES['datei']['tmp_name'];
echo $dir;
//Dateiendung herrausfinden
$typ = explode (".", $_FILES['datei']['name']);
$count = count($typ);
$count--;
echo "<br>$typ[$count]";
include ('GoogleTranslate.php');
$tr = new GoogleTranslate("en", "de");
echo $tr->translate("Hello World!");
Stichoza commented 10 years ago

Translation code works fine for me both on local and remote web servers. There is a problem with open_basedir settings in your PHP configuration. Take a look at this answer on stackoverflow.

Tropaion commented 10 years ago

Ok thank you, I will write a mail to my hoster. But the funny thing ist that the translation works....with error but it works.

Stichoza commented 10 years ago

I've pushed two commits https://github.com/Stichoza/google-translate-php/commit/1fee0dc668697ca9398299c6e13ca95d119ec71e and try with this version of code. Changed /tmp with sys_get_temp_dir() to get directory path used for temporary files.

P.S. There's a huge difference between Errors and Warnings

Tropaion commented 10 years ago

Yeah, sure. Okay, thank you for that code. I tried it, but the same error occurs. My hoster told me to control my program code. The path to webspace is /home/.sites/117/site3029/web.

By the way sys_get_temp_dir() output is /tmp - thats funny :smiley:

Now I made a folder with ftp with the permissions 777 and used the path /home/.sites/117/site3029/web/tmp. Now it works.

Stichoza commented 10 years ago

That's weird :smile: Okay, happy your code works. Good luck!

Tropaion commented 10 years ago

Yeah! Thanks for your help, and a great Code!