In our wiki exists several updated files. By example File:myfile.jpg. Then myfile.jpg is located in ../images/c/cf/myfile.jpg. I need to open (or download) directly (from a php program) the myfile.jpg. How the program can get the full path for myfile.jpg (../images/c/cf/myfile.jpg)?.
Topic on Project:Support desk
To access the physical path from the same server, it should be as simple as construct it from your upload directory, the /c/cf/ part, and the filename.
The /c/cf/ part is the first and 2 first (respectively) md5 sum hash characters of the filename (myfile.jpg). This can be done with the md5() function.
Thanks!!!
function path_from_md5fn_fn ($fn) {
$s = md5 ($fn);
return substr($s,0,1).'/'.substr($s,0,2).'/'.$fn;
}
http://path-to-your-wiki/Special:Redirect/file/myfile.jpg ?
@Ricordisamoa: Wonderful!, but the correct is:
http://path-to-your-wiki/index.php?title=Special:Redirect/file/myfile.jpg
Only if you don't have Short URLs set up.
A note to anyone else considering using this: The redirect will make it take longer for the file to start loading, and won't be cached (although the file which it redirects to will be).
Alternative, create Template:DirectFileOpen, with:
[http://path-to-your-wiki/index.php?title=Special:Redirect/file/{{{1}}} {{{2}}}]
That doesn't make any sense to do in a template. If you want a link directly to a file, you can just use [[Media:File.png]]
, and if you just want the URL you can use {{filepath:File.png}}
.
Thank you!
I changed: Template:DirectFileOpen:
[{{filepath:{{{1}}}}} {{{2}}}]
Because, perhaps it's easier write: {{DirectFileOpen|Filename|TextForFilename}} than [{{filepath:Filename}} TextForFilename].
Why are you still manually constructing an external link to a file instead of using Media:
? [[Media:Filename|TextForFilename]]
seems a lot easier than your template, and will actually count the file as being "used".
Because I do not want to open the page that references the file (i.g. File:Filename.jpg). I want to open the file directly.
This is because I want to open a rtf files. Obviously, a rtf file is not displayed in the page that contains the link (or my new template DirectFileOpen).
Very thank you!
And you obviously haven't tried to use Media: to see what results it gives...
I'm sorry, you are reason. I had thought that [[Media:]] was equivalent to [[File:]].
Media links directly to the file! I've already said this.
Very thanks!. You are right. I didn't prove it.