Replace directory path Drupal 6.20 - drupal

I try to guard a file, which I save from a form, in a path I specify. I use file_directory_path that returns the path to default, what do i do to change the path or to modify it to personalize it?
Code that this done but it does not function
$filepath='/sites/ficheros_profesores';
// str_replace(file_directory_path(),'',$filepath);
$file = file_save_upload('test',null,file_directory_path());
file_set_status($file, FILE_STATUS_PERMANENT);
Thanks

If I properly understood, you are trying to save the uploaded file in a folder which is inside the default 'files' directory, isn't it?
Instead str_replace, you could concatenate the strings with '.'. Simply:
$file = file_save_upload('test',null,file_directory_path().'/sites/ficheros_profesores');
You should then ensure that the '/sites/ficheros_profesores/' exists and that the 'www-data' user (asuming linux) has the proper permissions.
Hope it helps.

Related

SilverStripe 4.1 Email->addAttachment()?

I have a contact form that accepts a file input, I'd like to attach the file to the email that gets sent from the form.
Looking at the API reference isn't really helping, it states that the function expects a filepath with no clarification on anything beyond that.
The submit action will save a record of the into the database and this works correctly, something like:
$submission = MyDataObject::create();
$form->saveInto($submission);
$submission->write();
an Email object then gets created and sent. Both of these are functioning and working as expected.
Trying to attach the File I've tried:
$email->addAttachemnt($submission->MyFile()->Link());
which is the closest I can get to getting a filepath for the document. Dumping and pasting the resulting filepath being output by that call will download the form but that line throws an error and can't seem to locate the file.
I suspect that I'm misunderstanding what's supposed to be given to the function, clarification would be very much appreciated.
P.S. I don't currently have access to the code, I'm looking for some clarification on the function itself not an exact answer :).
In SilverStripe 4 the assets are abstracted away, so you can't guarantee that the file exists on your webserver. It generally will, but it could equally exist on a CDN somewhere for example.
When you handle files in SilverStripe 4 you should always use the contents of the file and whatever other metadata you have available, rather than relying on filesystem calls to load it.
This is how the silverstripe/userforms module attaches files to emails:
/** #var SilverStripe\Control\Email\Email $email */
$email->addAttachmentFromData(
$file->getString(), // stream of file contents
$file->getFilename(), // original filename
$file->getMimeType() // mime type
);
I would try $email->addAttachment($submission->MyFile()->Filename); If it doesn't work, you may need to prepend $_SERVER['DOCUMENT_ROOT'] to the filename.
$email->addAttachment($_SERVER['DOCUMENT_ROOT'] . $submission->MyFile()->Filename);

Grunt-init copyAndProcess function: Can I pass in multiple values to 'noProcess' option?

I'm using grunt-init to build a template for a site structure I repeat regularly.
The template.js file uses the init.copyAndProcess function to customize most of files but a few of them get corrupted by the file processing (some fonts and image files) and I want to include those files in the 'noProcess' option. If these files all existed in the same directory, I could use the noProcess option as mentioned in the documentation [ See: http://gruntjs.com/project-scaffolding#copying-files ] and pass in a string like and it works:
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: 'app/fonts/**'} );
Unfortunately the files that I need to have no processing performed on are not all in the same directory and I'd like to be able to pass in an array of them, something like the following block of code, but this does not work.
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: ['app/fonts/**', 'app/images/*.png', 'app/images/*.jpg']} );
Any thoughts on how I can have multiple targets for the 'noProcess' option?
As soon as I posted the question, I realized that my proposed code did work. I simply had an invalid path when I'd renamed my 'app' directory to 'dev'.

Where are files written to in R?

If I use the write method, where will these files be written? Example:
write(results, file="myFile.csv", ncolumns=1)
I don't specify a full path so I assume it's writing to some default directory. I checked program files, but it's not there. Suggestions on where to look?
If you type from within your R session:
getwd()
You should be able to retrieve your current working directory, that's the place where the files should be saved to.
You can also choose to set your workspace to a location of your desire:
setwd('C:/Users/.../Documents/R/Scripts')
Files you save will automatically be written to this new location.

Drools 5 load drl rule file from file system

I devloped a custom rule editor able to create drl file and save them in file system under a given directory. (e.g. c:\savedRules\rule.drl).
The problem is that once the rule is saved I need to run it with drools engine.
In my class I try to load rule in this way:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("c:\savedRules\rule.drl"), ResourceType.DRL);
but its doesn't work. the exception is "rule.drl cannot be opened because it does not exist" but it actually exists....
What am I doing wrong? Is there another way to load rules directly from file system?
Try using,
FileInputStream fis = new FileInputStream(drlFile);
kbuilder.add(ResourceFactory.newInputStreamResource(fis), ResourceType.DRL);
Thanks.
kbuilder.add(ResourceFactory.newClassPathResource("LoopConditionRules.drl"),ResourceType.DRL);
Just add this line and copy your drl file in resource folder of the project, when you will run it will automatically find the file from the project there is no need to give specific path for your file.
Try this way, may be you can get your required result.
Try the below code, this will work.
kbuilder.add(ResourceFactory.newFileResource(drlFileName), ResourceType.DRL);

file upload issue in drupal, all files are submitted to /tmp instead of location stated

Here is the code which I use to upload (drupal 6)
echo "DIR".$dir = drupal_get_path('module', 'modulename') . '/files';
if($docfile = file_save_upload('document',$dir))
echo "success:".$docfile->filepath;
It shows output as success:/tmp/Winter_0.jpg and I see the file uploaded to /tmp folder instead of my modulename/files folder. Can any one help me in fixing this.
You're calling file_save_upload with the wrong parameters. Refer to the file_save_upload API docs for the relevant information.
If I understood the syntax correctly, the following oughta work:
echo "DIR".$dir = drupal_get_path('module', 'modulename') . '/files';
if($docfile = file_save_upload('document', null, $dir))
echo "success:".$docfile->filepath;
Another possibility is that you need to tell Drupal that the file is not a temporary file.
file_set_status($file, FILE_STATUS_PERMANENT);
edit:
Just go with the link wimvds gave, read the docs, and test around what the correct syntax is. Perhaps the directory you are saving the file is wrong? Try /sites/all/files or /sites/default/files instead of trying to put it into the module folder where apache probably does not even have read/write rights, at least I'm unsure if Drupal lets us store files there.
Another take on reading the API would make me try file_save_upload($yourfile, array(), $destination_directory, FILE_EXISTS_REPLACE);

Resources