Member
Member
LondonLight.org   2014-06-12, 13:57
#1
Hey

I have some text in a .txt file which using class-textobject (or class-anyfile?) I treat as an image. How do I print the bare contents of this text file?
I tried many functions and only printCustomSizedImage* work, but they don't return bare contents.
I used: `<?php printCustomSizedImage(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); ?>`
This returns: `This is the content of foo.txt`

I would like pure text returned, nothing else. Is this possible?
Administrator
Administrator
acrylian   2014-06-12, 14:09
#2
You will have to use standard PHP function like `file_get_contents()` to read and display the plain file. Which is what the plugin uses to get it as well. See the `getContent()` method of it. You could also use `getContent()` and strip the wrapping span via `strip_tags`.
Member
Member
LondonLight.org   2014-06-12, 14:15
#3
And one more question, is it possible to print just the image filename without anything else? Like getUnprotectedImageURL minus the paths and minus the extension.
Member
Member
LondonLight.org   2014-06-12, 14:28
#4
Ooh thank you, I got it working! Though I don't know if what I did is either correct or efficient Smile Is this the best way to do it?
`<?php $txtContents = $_zp_current_image->getContent(); $txtContents = strip_tags($txtContents); echo $txtContents; ?>`
Member
Member
LondonLight.org   2014-06-12, 14:44
#5
I managed to get the full path without the extension using `<?php $txtFilename = getUnprotectedImageURL(); $txtFilename = stripSuffix($txtFilename); echo $txtFilename; ?>` which returns
/zp/albums/foo/bar/kitteh
Now how do I get rid of "/zp/albums/foo/bar/"?
Administrator
Administrator
acrylian   2014-06-12, 14:53
#6
`$txtFilename = str_replace(WEBPATH,'',$txtFilename)` should work. We have several of these constants like `WEBPATH`. I guess I should make a user guide entry about these some time.
Member
Member
LondonLight.org   2014-06-12, 15:03
#7
That one just removes "/zp".
Administrator
Administrator
acrylian   2014-06-12, 15:09
#8
Try `WEBPATH.'/'.ALBUMFOLDER.'/'.$_zp_current_album->name';
Member
Member
LondonLight.org   2014-06-12, 15:12
#9
Success!
`<?php $txtFilename = getUnprotectedImageURL(); $txtFilename = str_replace(WEBPATH.'/'.ALBUMFOLDER.'/'.$_zp_current_album->name.'/','',$txtFilename); $txtFilename = stripSuffix($txtFilename); echo $txtFilename; ?>`
Thank you!
Administrator
Administrator
acrylian   2014-06-12, 15:37
#10
Btw, of course `echo $_zp_current_image->filename` gets you the file name even easier. Textobjects are descendents of the image class so a lot works on them like on images. Sorry, forgot to mention earlier.
Member
Member
LondonLight.org   2014-06-28, 18:49
#11
For anyone interested, the pathinfo and stripsuffix functions works great for getting parts of a path or filename!

pathinfo returns an array consisting of dirname, basename and extension.
stripsuffix does as the name implies.

To get the txt filename:
`$txtFilename = pathinfo(getUnprotectedImageURL()); $txtFilename = $txtFilename ['basename'];`
To strip the suffix:
`$txtFilename = stripSuffix($txtFilename);`

You could shorten and merge the two:
`$txtFilename = pathinfo(getUnprotectedImageURL()); $txtFilename = stripSuffix($txtFilename ['basename']);`
Administrator
Administrator
acrylian   2014-06-28, 19:15
#12
Isn't what I told above much easier to get the filename? For other parts of paths there are several path related constants like WEBPATH, ALBUMFOLDER etc.
Member
Member
LondonLight.org   2014-06-28, 20:12
#13
I used the code you gave me above for some time, but once things started getting hairy I found this to be quicker to experiment with. Both have uses, hope this helps someone too Smile
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.