I've installed Drupal a couple of days ago in a new database to test it out for a later site migration. Trying to import a new language file now, enabled the Localization & Upload modules but I get this error whenever I import the .po file:

* The language French has been created.
* File upload error. Could not move uploaded file.

* warning: tempnam() has been disabled for security reasons in /var/www/vhosts/medalgerie.com/httpdocs/testing/includes/file.inc on line 228.
* warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access in /var/www/vhosts/medalgerie.com/httpdocs/testing/includes/file.inc on line 241.
* The translation import failed, because the file could not be read.
* The translation import of failed.

* 0/0 (0%) stings translated

I've done some research thru the forums, found that some people have had trouble with the "tempnam" function; the solutions provided didn't solve my problem. So, any help is greatly appreciated.

Comments

progga’s picture

Set Drupal's temporary directory to "files/temp" from "admin/settings/file-system" . Also make sure that the "files/" directory is writable. Then retry importing the language.

Epifrin’s picture

Thanks mate; I'll try that out. :)

beshox’s picture

your way did great job wiht me!, thanks a lot!

Epifrin’s picture

Man, this is tiring me. I still get the same error message; could it be because my shared host has the PHP Safe Mode on?!

progga’s picture

Can you please provide the output of "ls -lR" on your "files/" directory?

Epifrin’s picture

I didn't quite understand what you mean by "Is - IR", progga. If you could elaborate a little; I appreciate yoru effort.

I think it's an error of the Upload Module; seems like this doesn't only occur when importing a translation but when trying to attach a file to a forum message as well.

Deactivating the Safe Mode of PHP didn't seem to change anything. I also tried renaming the temp folder inside /files, to no avail. This is the error message I still get:

* File upload error. Could not move uploaded file.

* warning: tempnam() has been disabled for security reasons in ../includes/file.inc on line 228.
* warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpr8LhGg' to '' in ../includes/file.inc on line 241.

Epifrin’s picture

Can anyone suggest a way to go around this error?

progga’s picture

Looks like the root cause of the problem is tempnam(). The "disable_functions" directive in the php.ini might have been used to prevent its use. You can try running tempnam()'s example code from http://php.net/manual/ro/function.tempnam.php to findout whether it's really blocked. Or just execute this code from a php script:

echo ini_get('disable_function');

If tempnam() has been really banned, then it should be listed in the output.

Epifrin’s picture

Thanks alot. I'm going to try it out as soon as I find me a host that supports drupal.

DanPerTech’s picture

Have you fixed your problem concerning the language files? I have the same kind of problem, and I don't use drupal 6.x for this reason... Somebody told me to modify my .htaccess files to fix it, but can't tell you wich parameters to use...

Danny

ayalsule’s picture

if fixed the problem by creating my own tempnam() function in file.inc like this
alternative function

<?php
/**
 * create a temp file alternative to tempnam() because this functions disabled for security reasons 
 */
function dru_tempnam($dir,$prefix){
	$name = $prefix.md5(time().rand());
	$handle = fopen($dir.'/'.$name, "w");
	fclose($handle);
	return $dir.'/'.$name;
}
?>

change function in file_save_data() function and change fopen to file_put_content

<?php
/**
 * Save a string to the specified destination.
 *
 * @param $data A string containing the contents of the file.
 * @param $dest A string containing the destination location.
 * @param $replace Replace behavior when the destination file already exists.
 *   - FILE_EXISTS_REPLACE - Replace the existing file
 *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
 *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
 *
 * @return A string containing the resulting filename or 0 on error
 */
function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
  $temp = file_directory_temp();
  // On Windows, tempnam() requires an absolute path, so we use realpath().
  $file = dru_tempnam(realpath($temp), 'file');
  if (!file_put_contents($file, $data)) {
    drupal_set_message(t('The file could not be created.'), 'error');
    return 0;
  }

  if (!file_move($file, $dest, $replace)) {
    return 0;
  }

  return $file;
}
?>

...

polmaresma’s picture

This worked for me!

Thank's for your work.

Pol Maresma
PolNetwork.com