0

I want to append the name of a directory, say 'abc' to public:// uri of sites/default/files directory, such that it will point to the 'abc' directory inside sites/default/files.

Actually, whenever I try to do this file_move($file_object, 'public://abc', FILE_EXISTS_REPLACE) it moves the file inside sites/default/files and creates a file called 'abc'.

I want to move the file inside 'abc' directory, by appending 'abc' to public://, how do I do this?

I have searched for this and found that public://abc does the trick, but its not working for me.

4

Your function is telling drupal to move $file->filename to public://abc and hence renamed to abc. Drupal is doing what you are asking to do.

your $destination should be - 'public://abc/' . $file->filename

file_move($file, $destination, FILE_EXIST_REPLACE );

Below code should work (though not tested):

 $file = file_load($fid);
 $destination = 'public://abc/';
 if(file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
   file_move($file, $destination . $file->filename, FILE_EXIST_REPLACE);
 }
  • appending file name to the destination gives error – subhojit777 Jun 7 '12 at 9:14
  • can you pastebin your code? and whats the error that you are getting? – Dipen Jun 7 '12 at 9:15
  • its same as I mentioned in the question, here you will find the details pastebin.com/JwjJbLJp – subhojit777 Jun 7 '12 at 9:45
  • Can you specify the error in detail? Are you sure that the directory exist? why dont you use file_prepare_directory to check and see if it exist. – Dipen Jun 7 '12 at 10:21
  • Try this - pastebin.com/5pyYDzSU – Dipen Jun 7 '12 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.