Topic on Project:Support desk

[RESOLVED] Call to uploaded file

15
Jmarchn (talkcontribs)

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)?.

Ciencia Al Poder (talkcontribs)

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.

Jmarchn (talkcontribs)

Thanks!!!

function path_from_md5fn_fn ($fn) {
  $s = md5 ($fn);
  return substr($s,0,1).'/'.substr($s,0,2).'/'.$fn;
}
Ricordisamoa (talkcontribs)

http://path-to-your-wiki/Special:Redirect/file/myfile.jpg ?

Jmarchn (talkcontribs)

@Ricordisamoa: Wonderful!, but the correct is:

http://path-to-your-wiki/index.php?title=Special:Redirect/file/myfile.jpg

121.220.14.39 (talkcontribs)

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).

Jmarchn (talkcontribs)

Alternative, create Template:DirectFileOpen, with:

[http://path-to-your-wiki/index.php?title=Special:Redirect/file/{{{1}}} {{{2}}}]

121.220.14.39 (talkcontribs)

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}}.

Jmarchn (talkcontribs)

Thank you!

I changed: Template:DirectFileOpen:

[{{filepath:{{{1}}}}} {{{2}}}]

Because, perhaps it's easier write: {{DirectFileOpen|Filename|TextForFilename}} than [{{filepath:Filename}} TextForFilename].

121.220.14.39 (talkcontribs)

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".

Jmarchn (talkcontribs)

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!

Ciencia Al Poder (talkcontribs)

And you obviously haven't tried to use Media: to see what results it gives...

Jmarchn (talkcontribs)

I'm sorry, you are reason. I had thought that [[Media:]] was equivalent to [[File:]].

120.144.62.72 (talkcontribs)

Media links directly to the file! I've already said this.

Jmarchn (talkcontribs)

Very thanks!. You are right. I didn't prove it.

Reply to "[RESOLVED] Call to uploaded file"