PDA

View Full Version : Need some small (I think) help!



DannLea
21-03-2011, 10:54 AM
Hey HXFers! How are you today? Nice weather, is it not?

Anyhow, I am remaking a nonprofit youth related website and this time around I am using a flat file based CMS.. makes it easier for me and the person who will be using the backend updater.

So, that said, the guy who will be using the CMS will be using an uploader function to upload .PDF files to the website. The PDF files will be for various things, but mostly just to donators and supporters updates of what's going on.

SO, I need some help on this part of the race.

The code I'm using to show the contents of the folder the PDF files are in is this:

<?php
if ($handle = opendir('../updates/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<div align=\"center\"> <a target=\"devotions\" href=\"".$file."\">".$file."</a></div><br />";
}
}
closedir($handle);
}
?>

So I need to do two things with this that aren't currently working.

1. I want to have it so when the PHP uses the echo function to display the files, it does not show the file extention (i.e. 03.21.2011.PDF, I want the .PDF to remain hidden). How do I do this, or is it possible? I know I need to change the ".$file.", but I don't know what I need to change it to.

2. In all pages for the flat editor the man running the CMS can edit the pages.. Right now it looks like when you open a .html file in Notepad, you see all the HTML and no formatting options are avaliable.
I'm wondering if someone can give me a code for the text boxes that will put formatting buttons (B will add <b></b> tags, U will add <u></u> tags).. I'd really appreciate that!


Now I don't know how hard these things are, but I would VERY much appreciate it if someone could help me out! Even if you know how to do one thing, It would help for you to post that too!

Thanks in advance!,
Daniel

Trinity
21-03-2011, 12:18 PM
1. I'm sure there's a really, really easy way to do that, I just can't remember what it is. I guess you could explode('.', $file) and echo everything before the last item in the array. Or if the extension is always .PDF (or some other 3 letter extension), just remove the last 4 characters. I'm 99% certain I've seen a much more straightforward way to do it though :(

2. You could use one of these:
http://developer.yahoo.com/yui/editor/
http://tinymce.moxiecode.com/tryit/full.php
Or just google 'rich text editor'.

DannLea
21-03-2011, 07:22 PM
1. I'm sure there's a really, really easy way to do that, I just can't remember what it is. I guess you could explode('.', $file) and echo everything before the last item in the array. Or if the extension is always .PDF (or some other 3 letter extension), just remove the last 4 characters. I'm 99% certain I've seen a much more straightforward way to do it though :(

2. You could use one of these:
http://developer.yahoo.com/yui/editor/
http://tinymce.moxiecode.com/tryit/full.php
Or just google 'rich text editor'.

Thank you very much, the editor is working perfect and is doing just what I need it to!

How would I go about removing the last 3 letters, though? It will always be .PDf, .doc, or .txt, but it CAN be set up for only .PDF, that wouldn't be a problem if needed. What you see for PHP is as far as I've learned so far hahaha.

Also, I'm looking to order the files in the order of upload.. Most recent will be first, oldest will be last. Any way to do that?

badboyxlr
21-03-2011, 09:40 PM
if ($handle = opendir('../updates/')) {
while (false !== ($file = readdir($handle))) {
$index='$file != "index.php"||$file != "index.html"||$file != "index.asp"';
if ($file != "." && $file != "..") {
if (!$index){
$file=explode(".", $file);
$extention=$file['1'];//file extention
$file=$file['0'];//file name
echo "<div align=\"center\"> <a target=\"devotions\" href=\"".$file."\">".$file."</a></div><br />";
}
}
}
closedir($handle);
}

Trinity
21-03-2011, 11:12 PM
if ($handle = opendir('../updates/')) {
while (false !== ($file = readdir($handle))) {
$index='$file != "index.php"||$file != "index.html"||$file != "index.asp"';
if ($file != "." && $file != "..") {
if (!$index){
$file=explode(".", $file);
$extention=$file['1'];//file extention
$file=$file['0'];//file name
echo "<div align=\"center\"> <a target=\"devotions\" href=\"".$file."\">".$file."</a></div><br />";
}
}
}
closedir($handle);
}

I'm pretty sure that $index = 'blabla' line combined with the if(!$index) is pointless. You're setting $index as a weird string then checking if $index is true (contains anything). Of course it does, you just set it.

Edit: My mistake, you were checking if it's false (contains nothing)

Also, the method you've used to remove the file extension won't work if there are any dots in the file name. That's why I said to remove the last item in the array, not the second.


Thank you very much, the editor is working perfect and is doing just what I need it to!

How would I go about removing the last 3 letters, though? It will always be .PDf, .doc, or .txt, but it CAN be set up for only .PDF, that wouldn't be a problem if needed. What you see for PHP is as far as I've learned so far hahaha.

Also, I'm looking to order the files in the order of upload.. Most recent will be first, oldest will be last. Any way to do that?

To remove the last 3 letters (plus the dot, so 4 characters), use substr.


$removed = substr($file, 0, -4);


For ordering the files, I'd probably load all of the details into an array and use a combination of filectime() and sort(). My head's not working at the moment though, maybe there's a better way.

badboyxlr
21-03-2011, 11:14 PM
the index string is getting rid of the index.html .asp and .php files so there not echo'ed

you can always count the arrays, and -1 then add the others together ...

Trinity
21-03-2011, 11:20 PM
the index string is getting rid of the index.html .asp and .php files so there not echo'ed

you can always count the arrays, and -1 then add the others together ...

I'm pretty sure it isn't.
I'm not so sure that the second part of your post makes sense.
Edit: Wait, I just deciphered it, my bad. Be clearer, yo.

badboyxlr
21-03-2011, 11:23 PM
correct, i added an extra ! it should be if ($index){//code}

Trinity
21-03-2011, 11:26 PM
correct, i added an extra ! it should be if ($index){//code}

No, that wasn't my problem with it. That method of checking doesn't work, unless it's some freaky voodoo code that I've never seen before. Although I just tested it and it didn't work so I doubt it's voodoo magic.

You are setting a static string, then checking if there is anything in the string. PHP does not evaluate or even notice any of the operators in that string.

DannLea
22-03-2011, 12:36 AM
the index string is getting rid of the index.html .asp and .php files so there not echo'ed

you can always count the arrays, and -1 then add the others together ...

I understand what you mean as for the first point.. I got that far. As for the -1 arrays etc. thing, you've lost me! :P I code mainly HTML and CSS, and that's it really. More of a web designer to be honest :P I'm just trying to get this website working for the organization.


I'm pretty sure that $index = 'blabla' line combined with the if(!$index) is pointless. You're setting $index as a weird string then checking if $index is true (contains anything). Of course it does, you just set it.

Edit: My mistake, you were checking if it's false (contains nothing)

Also, the method you've used to remove the file extension won't work if there are any dots in the file name. That's why I said to remove the last item in the array, not the second.



To remove the last 3 letters (plus the dot, so 4 characters), use substr.


$removed = substr($file, 0, -4);


For ordering the files, I'd probably load all of the details into an array and use a combination of filectime() and sort(). My head's not working at the moment though, maybe there's a better way.

K so I realize I'm supposed to put that snippit somewhere, but as for where in the code and what to implement it with, I'm clueless ahaha.

And for the ordering explanation, no idea what you're talking about hahaha.

I feel so embarrassed, I should really look into PHP more than I do D:

badboyxlr
22-03-2011, 04:20 PM
if you had realized, it is stopping the index files from being sent to the client.

$file != "index.php"||$file != "index.html"||$file != "index.asp" is the $index string. and when called in a if(){} function, it will be put into the if function. and $file != "index file" will stop the index file from being shown, and as i use this i know it works.

Want to hide these adverts? Register an account for free!