root/afridex/plugins/Flutter/RCCWP_GetFile.php @ 21

Revision 21, 4.6 kB (checked in by admin, 18 years ago)
RevLine 
[21]1<?php
2
3        require_once('../../../wp-config.php');
4
5        if ( ( isset($_SERVER['HTTPS']) && 'on' == strtolower($_SERVER['HTTPS']) ) && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
6                $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
7        elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
8                $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
9        unset($current_user);
10
11        if (!(is_user_logged_in() && current_user_can('edit_posts')))
12                die("Athentication failed!");
13
14        $imagesExts = array('gif','jpg','png');
15        $audiosExts = array('wav','mp3');
16       
17        $acceptedExtsString = "";
18       
19        function DownloadFile(){
20                global $acceptedExtsString, $imagesExts, $audiosExts;
21       
22                $url = $_POST['upload_url'];
23       
24                // Prepare accpeted extensions
25                $acceptedExts = array();
26       
27                if ('1' == $_POST['type'])
28                        $acceptedExts = $imagesExts;
29                elseif ('2' == $_POST['type']) 
30                        $acceptedExts = $audiosExts;
31       
32       
33                //Retrieve file
34                if ($fp_source = @fopen($url, 'rb')) {
35                        //Get target filename
36                        $exploded_url = explode( '.', $url );
37       
38                        $ext = array_pop( $exploded_url );
39       
40                        // Check extension
41                        if (false != $acceptedExts)
42                                if (false === array_search(strtolower($ext), $acceptedExts)){
43                                        foreach($acceptedExts as $acceptedExt)
44                                                if ($acceptedExtsString == "")
45                                                        $acceptedExtsString = $acceptedExt;
46                                                else
47                                                        $acceptedExtsString = $acceptedExtsString." - ".$acceptedExt;
48                                        return false;
49                                }
50                       
51       
52                        $filename = time() . '_' . str_replace( 'rc_cwp_meta_', '', $_POST["input_name"]) . '.' . $ext;
53                       
54                        $directory = dirname(__FILE__) . '/files_flutter/';
55       
56                        $fp_dest = @fopen($directory . $filename,"wb");
57                        if ($fp_dest == false) return false;
58       
59                        while(!feof($fp_source)) {
60                                set_time_limit(30);
61       
62                                //if (connection_status()!=0) return false;
63       
64                                $readData = fread($fp_source, 1024*2);
65                                //if ($readData == false) return false;
66                               
67                                fwrite($fp_dest,$readData);
68                               
69                        }
70                        fclose($fp_source) ;
71                        fclose($fp_dest) ;
72                        //chmod($directory . $filename, 0644);
73       
74                        return $filename;
75                }
76                return false;
77       
78        }
79
80        if (isset($_POST['upload_url']) && (!empty($_POST['upload_url'])))  // file was send from browser
81        {
82                if ( (substr($_POST['upload_url'],0,4) != "http") && (substr($_POST['upload_url'],0,3) != "ftp"))
83                        $_POST['upload_url'] = "http://".$_POST['upload_url'];
84
85                $filename = DownloadFile();
86               
87
88                if (false == $filename) {
89                        if ($acceptedExtsString != "") $infoStr = ". Make sure the file ends with: $acceptedExtsString";
90//                      $result_msg = "Error downloading file: ".$_POST['upload_url'].$infoStr;
91                        $result_msg = "<font color='red'><b>Upload Unsuccessful!</b></font>";
92                }
93                else{
94//                      $result_msg = 'The URL '.$_POST['upload_url'].' was downloaded successfuly. Please remember to click the save button.';
95                        $result_msg = "<font color='green'><b>Successful upload!</b></font>" ;
96                        $operationSuccess = "true";
97                }
98                include_once("RCCWP_WritePostPage.php") ;
99                $edit_anchor = RCCWP_WritePostPage::snipshot_anchor(FLUTTER_URI.'files_flutter/'.$filename) ;
100                echo $result_msg."*".$filename."*".$edit_anchor ;
101        }
102
103if( isset($_FILES['Filedata'] ) )
104{
105        if ($_FILES['Filedata']['error'] == UPLOAD_ERR_OK)  // no error
106        {
107                $special_chars = array (' ','`','"','\'','\\','/'," ","#","$","%","^","&","*","!","~","‘","\"","’","'","=","?","/","[","]","(",")","|","<",">",";","\\",",");
108                $filename = str_replace($special_chars,'',$_FILES['Filedata']['name']);
109                $filename = time() . $filename;
110                @move_uploaded_file( $_FILES['Filedata']['tmp_name'], dirname(__FILE__) . '/files_flutter/' . $filename );
111                @chmod(dirname(__FILE__) . '/files_flutter/' . $filename, 0644);
112
113//              $result_msg = 'The file '.$_FILES['Filedata']['name'].' was uploaded successfuly. Please remember to click the save button.';
114                $result_msg = "<font color='green'><b>Successful upload!</b></font>" ;
115                $operationSuccess = "true";
116        }
117        elseif ($_FILES['Filedata']['error'] == UPLOAD_ERR_INI_SIZE)
118                $result_msg = 'The uploaded file exceeds the maximum upload limit';
119        else 
120                $result_msg = "<font color='red'><b>Upload Unsuccessful!</b></font>";
121
122        include_once("RCCWP_WritePostPage.php") ;
123        $edit_anchor = RCCWP_WritePostPage::snipshot_anchor(FLUTTER_URI.'files_flutter/'.$filename) ;
124        echo $result_msg."*".$filename."*".$edit_anchor ;
125}
126/*
127        if( isset($_FILES['Filedata'] ) )
128        {
129                $path = dirname(__FILE__) . '/files_flutter/';
130                $path = $path . basename( $_FILES['Filedata']['name'] );
131                if( move_uploaded_file($_FILES['Filedata']['tmp_name'], $path) )
132                {
133                        echo 'The file was uploaded successfuly. Please remember to click the save button.'.$_FILES['Filedata']['name'] ;
134                }
135                else
136                {
137                        echo $_FILES[0]['error'] ;
138                }
139        }*/
140?>
Note: See TracBrowser for help on using the browser.