Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-19-2012, 01:15 PM   PM User | #1
graisbeck
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
graisbeck is an unknown quantity at this point
Problem with CMSFS allowing pdf's

Hi, I have a CMS from scratch website, when I want to add a link to a pdf file via an include, the file browser only shows .php files. The code I have below looks like thats the code I need changing to allow .pdf, .doc and .docx files, but I don't have a clue how to change it.
Some help would be greatly appreciated.

PHP Code:
<?PHP
    
require 'check-login.php' ;
    require 
'../cmsfns.php' ;
    
    
/*
        Params:
            $_GET['dir']  - The directory we're currently browsing
            $_GET['type'] - Limit the file extensions to show (currently only supports one, only 'php' used)
    */
    
    
if (isset($_GET['dir'])) {
        
// Strip off trailing slash if one exists
        
define ("DIR"rtrim($_GET['dir'],'/')) ;
    }
    else {
        
define ("DIR"'..') ;
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Browse content - <?PHP echo stripslashes($_SESSION['CMS_Title']) ; ?></title>
    <link href="styles.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" language="javascript" src="core.js"></script>
    <script type="text/javascript">
    <!--
        function selectPage(wotPage) {
            window.opener.sentLink(wotPage) ;
            window.close() ;
        }
    // -->
    </script>
    <style type="text/css">
        body {padding:1em;}
        h1 {
            font-size:1.5em;
        }
    </style>
</head>

<body class="">
<h1>Select page/file:</h1>
<div class="crumbNav">
    <?PHP
        
// Break down current location, linking to each folder..
        
$folders explode('/',DIR) ;
        
$levels sizeof($folders) ;
        
$link '' ;
        for (
$fldr=0$fldr<$levels$fldr++) {
            
$link .= $folders[$fldr] ;
            
$link .= '/' ;
            if (
$fldr $levels-1) {
                echo 
'<a href="?dir=' $link ;
                if (isSet(
$_GET['type'])) echo '&type=' $_GET['type'] ;
                echo 
'">' ;
            }
            if (
$folders[$fldr] == ".."$folders[$fldr] = "Home" ;
            echo 
' ' $folders[$fldr] ;
            if (
$fldr $levels-1) {
                echo 
'</a>' ;
            }
            echo 
' /' ;
        }
    
?>
</div>

<?PHP
    $handle 
opendir(DIR) ;
    
$itemsFound ;
    
$outputHTML '' ;
    
$outputDirs '' ;
    
$outputFiles '' ;
    while (
false !== ($file readdir($handle))) {
        
$previewFile getPreviewFileFromLive(DIR.'/'.$file) ;
        if (
strstr($file'phpthumb') || strstr($file'phpthumb') || !file_exists($previewFile)) {
            continue ;
        }
        if (
                (!
in_array($file$reserved_filenames) && !in_array('../'.$file$reserved_filenames) )
                ||
                (
$file == 'cmsfiles')
            ) {
            
$itemsFound++ ;
            if (
is_dir(DIR.'/'.$file)) {
                
// Directory
                
$outputDirs .= "\n<li class=\"dir\">" ;
                
$outputDirs .= '<a href="?dir=' DIR .'/'$file ;
                if (isSet(
$_GET['type'])) $outputDirs .= '&type=' $_GET['type'] ;
                
$outputDirs .= '" title="Browse ' $file '">' ;
                
$outputDirs .= $file ;
                
$outputDirs .= '</a></li>' ;
            }
            else if (isSet(
$_GET['type'])) {
                if (
$_GET['type'] == 'php' && getFileExtension($file) == 'php') {
                    
// Page link
                    
$outputFiles .= "\n" '<li class="file page"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                    
$outputFiles .= $file ;
                    
$outputFiles .= '</a>' ;
                    
$outputFiles .= "\n</li>" ;
                }
                else if (
$_GET['type'] == getFileExtension($file) ) {
                    
// Other matching file
                    
$outputFiles .= "\n" '<li class="file"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                    
$outputFiles .= $file ;
                    
$outputFiles .= '</a>' ;
                    
$outputFiles .= "\n</li>" ;
                }
            }
            else {
                
// Unspecified (i.e. 'File' type link)
                
$outputFiles .= "\n" '<li class="file"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                
$outputFiles .= $file ;
                
$outputFiles .= '</a>' ;
                
$outputFiles .= "\n</li>" ;
            }
        }
    }
    
closedir($handle) ;
    
    if (
$itemsFound 0) {
        
$outputHTML '<div class="bigLinks"><ul>' $outputDirs $outputFiles '<!-- 3 --></ul></div>' ;
    }
    else {
        
$outputHTML .= '<div><span class="info">No files or folders found</span></div>' ;
    }
    
    echo 
$outputHTML ;
?>



</body>
</html>

Last edited by graisbeck; 09-19-2012 at 01:18 PM..
graisbeck is offline   Reply With Quote
Old 09-21-2012, 10:57 PM   PM User | #2
graisbeck
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
graisbeck is an unknown quantity at this point
So to simplify:
Where in this code do I add a pdf file extension please?
PHP Code:
<?PHP
    $handle 
opendir(DIR) ;
    
$itemsFound ;
    
$outputHTML '' ;
    
$outputDirs '' ;
    
$outputFiles '' ;
    while (
false !== ($file readdir($handle))) {
        
$previewFile getPreviewFileFromLive(DIR.'/'.$file) ;
        if (
strstr($file'phpthumb') || strstr($file'phpthumb') || !file_exists($previewFile)) {
            continue ;
        }
        if (
                (!
in_array($file$reserved_filenames) && !in_array('../'.$file$reserved_filenames) )
                ||
                (
$file == 'cmsfiles')
            ) {
            
$itemsFound++ ;
            if (
is_dir(DIR.'/'.$file)) {
                
// Directory
                
$outputDirs .= "\n<li class=\"dir\">" ;
                
$outputDirs .= '<a href="?dir=' DIR .'/'$file ;
                if (isSet(
$_GET['type'])) $outputDirs .= '&type=' $_GET['type'] ;
                
$outputDirs .= '" title="Browse ' $file '">' ;
                
$outputDirs .= $file ;
                
$outputDirs .= '</a></li>' ;
            }
            else if (isSet(
$_GET['type'])) {
                if (
$_GET['type'] == 'php' && getFileExtension($file) == 'php') {
                    
// Page link
                    
$outputFiles .= "\n" '<li class="file page"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                    
$outputFiles .= $file ;
                    
$outputFiles .= '</a>' ;
                    
$outputFiles .= "\n</li>" ;
                }
                else if (
$_GET['type'] == getFileExtension($file) ) {
                    
// Other matching file
                    
$outputFiles .= "\n" '<li class="file"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                    
$outputFiles .= $file ;
                    
$outputFiles .= '</a>' ;
                    
$outputFiles .= "\n</li>" ;
                }
            }
            else {
                
// Unspecified (i.e. 'File' type link)
                
$outputFiles .= "\n" '<li class="file"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                
$outputFiles .= $file ;
                
$outputFiles .= '</a>' ;
                
$outputFiles .= "\n</li>" ;
            }
        }
    }
    
closedir($handle) ;
    
    if (
$itemsFound 0) {
        
$outputHTML '<div class="bigLinks"><ul>' $outputDirs $outputFiles '<!-- 3 --></ul></div>' ;
    }
    else {
        
$outputHTML .= '<div><span class="info">No files or folders found</span></div>' ;
    }
    
    echo 
$outputHTML ;
?>
graisbeck is offline   Reply With Quote
Old 09-21-2012, 11:14 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,500
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Hi

Sorry you've not had any replies yet. I've got to be honest and tell you that what you're asking is about as clear as mud. I didn't understand your first post and I don't understand your followup either. To you, you know what you're talking about, what your project is, what you want it to do etc. To us, you're asking a random question about adding .pdf files and where to change the extension.

Let me give you an example..

I'm working on my own CMS with modules / plugins. It works ok but in the database i need to know how to find what other modules depend on a module. I found some code i think will do the job <imagine php code here> but I've not got a clue what to do with it.

Would you understand any of that or be able to understand it clearly?

Quote:
Originally Posted by graisbeck View Post
when I want to add a link to a pdf file via an include, the file browser only shows .php files. The code I have below looks like thats the code I need changing to allow .pdf, .doc and .docx files, but I don't have a clue how to change it.
If the code you have looks like it'll do what you want, you should be skilled enough to know how to re-write it. If you're not, how can you be sure you've go the code that does what you think it does? You say the file browser only shows php files.. What do you mean by this? Is it an online file manager? Online php editor? Or is it a download prompt asking you to save a .php file?

Why do you need to add file extensions? - To make it scan files, output a download header? - You're not telling us much but expecting us to know the answers.

Quote:
Originally Posted by graisbeck View Post
So to simplify:
Where in this code do I add a pdf file extension please?
Again, until we have a better explanation, you're not going to get any answers from us as we simply can't help despite your politeness. You need to describe the project, scenario, problem and the result you'd like a bit clearer.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 09-23-2012, 01:06 AM   PM User | #4
graisbeck
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
graisbeck is an unknown quantity at this point
tangoforce, thank you for taking the time to explain that to me. I'll try and describe the problem I'm having more clearly.

Firstly I browse and upload a file (PHP, PDF or DOC) to mycms>mycmsfiles directory.
When I go into my fckeditor and want to add a hyperlink to my content, I click 'Insert link' in my fckeditor, which opens a file browser. The problem is that the file browser window only shows PHP files, it does not give me the choice of selecting a PDF or DOC file.
I'm no expert at PHP, but I believe the code below determines which directorys and file extensions the file browser displays.

PHP Code:
<?PHP
    $handle 
opendir(DIR) ;
    
$itemsFound ;
    
$outputHTML '' ;
    
$outputDirs '' ;
    
$outputFiles '' ;
    while (
false !== ($file readdir($handle))) {
        
$previewFile getPreviewFileFromLive(DIR.'/'.$file) ;
        if (
strstr($file'phpthumb') || strstr($file'phpthumb') || !file_exists($previewFile)) {
            continue ;
        }
        if (
                (!
in_array($file$reserved_filenames) && !in_array('../'.$file$reserved_filenames) )
                ||
                (
$file == 'cmsfiles')
            ) {
            
$itemsFound++ ;
            if (
is_dir(DIR.'/'.$file)) {
                
// Directory
                
$outputDirs .= "\n<li class=\"dir\">" ;
                
$outputDirs .= '<a href="?dir=' DIR .'/'$file ;
                if (isSet(
$_GET['type'])) $outputDirs .= '&type=' $_GET['type'] ;
                
$outputDirs .= '" title="Browse ' $file '">' ;
                
$outputDirs .= $file ;
                
$outputDirs .= '</a></li>' ;
            }
            else if (isSet(
$_GET['type'])) {
                if (
$_GET['type'] == 'php' && getFileExtension($file) == 'php') {
                    
// Page link
                    
$outputFiles .= "\n" '<li class="file page"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                    
$outputFiles .= $file ;
                    
$outputFiles .= '</a>' ;
                    
$outputFiles .= "\n</li>" ;
                }
                else if (
$_GET['type'] == getFileExtension($file) ) {
                    
// Other matching file
                    
$outputFiles .= "\n" '<li class="file"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                    
$outputFiles .= $file ;
                    
$outputFiles .= '</a>' ;
                    
$outputFiles .= "\n</li>" ;
                }
            }
            else {
                
// Unspecified (i.e. 'File' type link)
                
$outputFiles .= "\n" '<li class="file"><a href="javascript:selectPage(\'' DIR '/' $file '\');" >' ;
                
$outputFiles .= $file ;
                
$outputFiles .= '</a>' ;
                
$outputFiles .= "\n</li>" ;
            }
        }
    }
    
closedir($handle) ;
    
    if (
$itemsFound 0) {
        
$outputHTML '<div class="bigLinks"><ul>' $outputDirs $outputFiles '<!-- 3 --></ul></div>' ;
    }
    else {
        
$outputHTML .= '<div><span class="info">No files or folders found</span></div>' ;
    }
    
    echo 
$outputHTML ;
?>
What I want to know is if it is possible to add PDF and DOC extensions to the code so that they will be available to select in the file browser window?
I'm sure this is the snippet from above which allows PHP extensions:
PHP Code:
 if ($_GET['type'] == 'php' && getFileExtension($file) == 'php') { 
Thanks for any help.

Last edited by graisbeck; 09-23-2012 at 01:07 AM.. Reason: Typo
graisbeck is offline   Reply With Quote
Old 10-02-2012, 01:00 PM   PM User | #5
graisbeck
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
graisbeck is an unknown quantity at this point
Bumping
graisbeck is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:07 AM.


Advertisement
Log in to turn off these ads.