drupal 7 how to use drupal_goto for file - drupal-7

I did some custom scripting in a custom module. After my scripting I would like to go to the file path of a file field.
How can I achive this?
I have the uri of the file to display it.
I tried
drupal_goto('$result')
where $result is result of query with uri field of file.
Although
drupal_goto($result) does not work.
Any suggestions??

drupal_goto(file_create_url($result));
The uri contains public://
If this doesnt work, print the result of file_create_url($result) and copy past it in your browser see if the file is really there. By the way, you should avoid querying the database just for one file and use a file_load() to avoid bad surprises.

Thanks this realy helped me in the good direction...
Now I used this
$file = file_load($fid);
$uri = $file->uri;
$url = file_create_url($uri);
drupal_goto($url);
Hope this will help someone :-)

Related

Dynamic URL and Sheet using =Importange

I'm trying to make a =ImportRange with a dynamic URL and Sheet, but I'm doing something wrong.
https://i.stack.imgur.com/QQRDK.png
I've also tryed with ""=Q24"A3:A3") where Q24 = August-September !, but that also give an error.
I want to do the same thing with the URL, but I also get an error when I try to do that.
Is it possible and if, which command do i need to use.
I hope someone could help me.
Br
Anders
use:
=IMPORTRANGE("1HeGmCh3fFgHAfJSIsCIFkFi48PWpXR0iZdBcv4HhSWw"; Q24&"!A3")

CakePHP: Convert plain text to clickable link

I'm still pretty new to CakePHP and am wondering if there is a built-in function that takes a string, looks for any URLs it may contain, and converts any URLs it finds into clickable links. I couldn't find anything in the CakePHP documentation and a quick Google search didn't find anything either. I know that CakePHP has some things that aren't fully documented, though. Any ideas? Thanks!
http://book.cakephp.org/view/1469/Text
you can try something like this regex magic:
$stringValue = 'bla blubb http://foobar.com test123';
$pregPattern = '/.*http:\/\/.*? .*/i';
$stringValue = preg_replace($pregPattern, '$1$2$3', $stringValue);
note: the '.*?' part can be improved by accepting URL encoded chars

Modify Filename Before Saving in Django using model.FileField

I have a model.FileField(upload_to='%Y/%m/%d') field. This works great; however, I want to rename the file based on the context of the user uploading the file before it is saved. Is there a way of modifying the request object before it saved to accomplish this?
I have come across people with similar issues but the answers always point back to the Django documentation. I have tried figuring this out using the documentation but can't. Can someone provide some code to show hot to solve this?
Thanks in advance.
you can use function for upload_to value with instance and filename inputs and return path and file name
for example:
def upload_to_func(instance, filename):
now = datetime.now()
return os.path.join(str(now.year), str(now.month), str(now.day), filename)
field_x = model.FileField(upload_to=upload_to_func)
you can change path and filename in function

Ampersand in URL

i'm developing cakephp application.
i need some specific characters in url, like & (ampersand), because i need it for search purpose.
but, if i have ampersand in my url (like http://localhost/myapp/publications/index/string:Mono%20Manana/tags:publisher), it is rewrited and redirected as default url (in this case http://localhost/myapp/).
can you help me how to solve this and to use all kind of strings in my application.
thank you in advance!
ok, just to mention that i did find solution, not with urlencode, but using base64_encode. hopefully it will do the job...
Did you use urlencode()?
Some of your source code would really help us to see what's going on.

Linking to a file (e.g. PDF) within a CakePHP view

I'd like to link to some PDFs in one of my controller views. What's the best practice for accomplishing this? The CakePHP webroot folder contains a ./files/ subfolder, I am confounded by trying to link to it without using "magic" pathnames in my href (e.g. "/path/to/my/webroot/files/myfile.pdf").
What are my options?
EDIT: I didn't adequately describe my question. I was attempting to link to files in /app/webroot/files/ in a platform-agnostic (ie. no mod_rewrite) way.
I've since worked around this issue by storing such files outside the CakePHP directory structure.
$html->link('Pdf', '/files/myfile.pdf');
This is somewhat tangential, but for access to such a location in Models and other places you can simply do this:
$file = WWW_ROOT . DS . 'files' . DS;
This tactic might be helpful to someone accessing files for static data loading, such as XML or JSON.
This is not recommended for public consumption or public linking.
I can confirm that this is an issue when mod_rewrite is not being used.
<?php echo $html->link('pdf', '/files/test.pdf'); ?>
outputs
pdf
it should output
pdf
This should work
<?php echo $html->link('pdf', $this->webroot('files'.DS.'test.pdf'); ?>
I'm not sure I understand the question correctly, but here goes. Basically any file you put in the webroot folder will be accessible on the webserver, so if you put the file in webroot/files/file.pdf you would simply link to /files/file.pdf.
If that doesn't work, please clarify your question...
or..
Link Text
:)
or...
Link Text
Descargar Archivo

Resources