Skip to main content
Tweeted twitter.com/StackDrupal/status/1402052795726024707
added 39 characters in body
Source Link
albertski
  • 3.5k
  • 4
  • 25
  • 48

I am programmatically importing images and saving them via file_save_data();

$fileContentsPath = 'http://mypathtofile.com';
$uri = 'public://myfolder/mysecondfolder/filename.jpg';
$image = @file_get_contentsfile_get_contents($fileContentsPath);
$file = file_save_data($image, $uri, FILE_EXISTS_REPLACE);

When I run this I get the following error: The specified file temporary://fileJ4LL4o could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.

MyI am pretty sure my temporary directory is configured correctly and the files folder is assigned to the apache user.

If I go ininto the files directory and make the directories (myfolder/mysecondfolder) via command line and rerun it works correctly.

So the problem is that if the folders don't exist from the $uri path, it fails instead of creating the folders.

I am programmatically importing images and saving them via file_save_data();

$fileContentsPath = 'http://mypathtofile.com';
$uri = 'public://myfolder/mysecondfolder/filename.jpg';
$image = @file_get_contents($fileContentsPath);
$file = file_save_data($image, $uri, FILE_EXISTS_REPLACE);

When I run this I get the following error: The specified file temporary://fileJ4LL4o could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.

My temporary directory is configured correctly and the files folder is assigned to the apache user.

If I go in and make the directories (myfolder/mysecondfolder) via command line and rerun it works correctly.

So the problem is that if the folders don't exist from the $uri path, it fails instead of creating the folders.

I am programmatically importing images and saving them via file_save_data();

$fileContentsPath = 'http://mypathtofile.com';
$uri = 'public://myfolder/mysecondfolder/filename.jpg';
$image = file_get_contents($fileContentsPath);
$file = file_save_data($image, $uri, FILE_EXISTS_REPLACE);

When I run this I get the following error: The specified file temporary://fileJ4LL4o could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.

I am pretty sure my temporary directory is configured correctly and the files folder is assigned to the apache user.

If I go into the files directory and make the directories (myfolder/mysecondfolder) via command line and rerun it works correctly.

So the problem is that if the folders don't exist from the $uri path, it fails instead of creating the folders.

Source Link
albertski
  • 3.5k
  • 4
  • 25
  • 48

If folders don't exist in URI path, file_save_data() fails

I am programmatically importing images and saving them via file_save_data();

$fileContentsPath = 'http://mypathtofile.com';
$uri = 'public://myfolder/mysecondfolder/filename.jpg';
$image = @file_get_contents($fileContentsPath);
$file = file_save_data($image, $uri, FILE_EXISTS_REPLACE);

When I run this I get the following error: The specified file temporary://fileJ4LL4o could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.

My temporary directory is configured correctly and the files folder is assigned to the apache user.

If I go in and make the directories (myfolder/mysecondfolder) via command line and rerun it works correctly.

So the problem is that if the folders don't exist from the $uri path, it fails instead of creating the folders.