root/afridex/plugins/Flutter/RCCWP_upload.php

Revision 21, 5.8 kB (checked in by admin, 18 years ago)
Line 
1<?php
2require( dirname(__FILE__) . '/../../../wp-config.php' );
3if (!(is_user_logged_in() && current_user_can('edit_posts')))
4        die("Athentication failed!");
5?>
6
7<html>
8<head>
9
10<?php
11
12if (isset($_POST['fileframe'])) 
13{
14        $operationSuccess = "false";
15        // A file is uploaded
16        if (isset($_FILES['file']) && (!empty($_FILES['file']['tmp_name'])))  // file was send from browser
17        {
18               
19                if ($_FILES['file']['error'] == UPLOAD_ERR_OK)  // no error
20                {
21                        $special_chars = array (' ','`','"','\'','\\','/'," ","#","$","%","^","&","*","!","~","‘","\"","’","'","=","?","/","[","]","(",")","|","<",">",";","\\",",");
22                        $filename = str_replace($special_chars,'',$_FILES['file']['name']);
23                        $filename = time() . $filename;
24                        @move_uploaded_file( $_FILES['file']['tmp_name'], dirname(__FILE__) . '/files_flutter/' . $filename );
25                        @chmod(dirname(__FILE__) . '/files_flutter/' . $filename, 0644);
26
27//                      $result_msg = 'The file '.$_FILES['file']['name'].' was uploaded successfuly. Please remember to click the save button.';
28                        $result_msg = "<font color=\"green\"><b>Successful upload!</b></font>" ;
29                        $operationSuccess = "true";
30                }
31                elseif ($_FILES['file']['error'] == UPLOAD_ERR_INI_SIZE)
32                        $result_msg = 'The uploaded file exceeds the maximum upload limit';
33                else 
34//                      $result_msg = 'The upload failed';
35                        $result_msg = "<font color=\"red\"><b>Upload Unsuccessful!</b></font>";
36       
37        }
38
39        // If operation is success, make sure the file was created properly
40        if ($operationSuccess == "true"){
41                if ($fp_check_file = @fopen(dirname(__FILE__) . '/files_flutter/' . $filename, 'rb')) {
42                        fclose($fp_check_file);
43                }
44                else{
45                        $operationSuccess = "false";
46                        $result_msg = "Failed to upload the file!";
47                }
48               
49        }
50
51
52       
53
54?>
55
56        <script language="javascript">
57
58                // The code that runs after the file is uploaded
59        var par = window.parent.document;
60                var iframe = par.getElementById('upload_internal_iframe_<?php echo $_POST["input_name"]?>');
61                par.getElementById('upload_progress_<?php echo $_POST["input_name"]?>').innerHTML = '<?php echo $result_msg?>';
62                iframe.style.display="";
63
64                if (<?php echo $operationSuccess?>){
65                        par.getElementById("<?php echo $_POST["input_name"]?>").value = "<?php echo $filename?>";
66                       
67                        //Set image
68                        <?php
69                                $newImagePath = FLUTTER_URI.'phpThumb.php?&w=150&h=120&src='.urlencode(FLUTTER_URI.'files_flutter/'.$filename);
70                                include_once("RCCWP_WritePostPage.php") ;
71                                $edit_anchor = RCCWP_WritePostPage::snipshot_anchor($newImagePath) ;
72                                if (isset($_POST['imageThumbID'])){ 
73                        ?>
74                                if( par.getElementById('<?php echo $_POST['imageThumbID']; ?>') )
75                                {
76                                        par.getElementById('<?php echo $_POST['imageThumbID']; ?>').src = "<?php echo $newImagePath;?>";
77                                        var s = "<a class='thickbox' href='#impossible_location' onclick=\"call_thickbox('<?php echo $edit_anchor ?>')\" >";
78                                        var e = "<strong onclick=prepareUpdatePhoto('<?php echo $_POST['input_name'] ?>')>Edit</strong> </a>" ;
79                                        par.getElementById("photo_edit_link_<?php echo $_POST['input_name'] ?>").innerHTML = s+e ;
80                                }
81                        <?php } ?>
82                }
83               
84               
85               
86        </script>
87
88
89<?php
90        //exit()
91
92}
93?>
94
95<script language="javascript">
96function upload(){
97        // hide old iframe
98        var par = window.parent.document;
99
100        var iframe = par.getElementById('upload_internal_iframe_<?php echo $_GET["input_name"]?>');
101        iframe.style.display="none";//height = '0px';
102               
103        // update progress
104        par.getElementById('upload_progress_<?php echo $_GET["input_name"]?>').style.visibility = "visible";
105        par.getElementById('upload_progress_<?php echo $_GET["input_name"]?>').style.height = "auto";
106        par.getElementById('upload_progress_<?php echo $_GET["input_name"]?>').innerHTML = "Transferring ";
107
108
109        setTimeout("transferring(0)",1000);
110       
111        // send
112        document.iform.submit();
113       
114        //iframe.style.visibility = 'hidden';
115        //par.getElementById('upload_progress').style.visibility = "hidden";
116}
117
118function transferring(dots){
119       
120        newString = "Transferring ";
121        for (var x=1; x<=dots; x++) {
122                newString = newString + ".";
123        }
124       
125        var par = window.parent.document;
126
127        // update progress
128        if (par.getElementById('upload_progress_<?php echo $_GET["input_name"]?>').innerHTML.substring(0,5) != "Trans") return;
129        par.getElementById('upload_progress_<?php echo $_GET["input_name"]?>').innerHTML = newString;
130        if (dots == 4) dots = 0; else dots = dots + 1;
131        setTimeout("transferring("+dots+")",1000) ;
132       
133}
134
135</script>
136<style>
137body {
138        padding: 0px;
139        margin: 0px;
140        vertical-align:top;
141}
142</style>
143<link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/global.css' type='text/css' />
144<link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/wp-admin.css' type='text/css' />
145<link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/colors-fresh.css' type='text/css' />
146<style>
147body {
148        background: transparent;
149}
150</style>
151
152
153</head>
154<body>
155
156
157<form name="iform" action="" method="post" enctype="multipart/form-data">
158
159        <input type="hidden" name="fileframe" value="true" />
160       
161        <?php   
162                if (isset($_GET['imageThumbID'])) {
163                        echo '<input type="hidden" name="imageThumbID" value="'.$_GET['imageThumbID'].'" />';
164                }
165
166                if (isset($_GET['inputSize'])){
167                        $inputSize = $_GET['inputSize'];
168                }
169        ?>
170       
171
172        <table border="0" style="width:100%">
173
174                <tr>
175                        <?php if($_GET['canvas']!=0){ ?>
176                                <td width=17%><label for="file">File:</label><br />
177                                <input id="file" type="file" name="file" onchange="upload()" size="<?php echo $inputSize; ?>"/></td>
178                        <?php }else{ ?>
179                                <td width=17%><label for="file">File:</label></td>
180                                <td><input id="file" type="file" name="file" onchange="upload()" size="<?php echo $inputSize; ?>"/></td>
181                        <?php } ?>
182                </tr>
183
184        </table>
185
186       
187        <input type="hidden" name="fileframe" value="true" />
188        <input type="hidden" name="imgnum" />
189        <input type="hidden" name="input_name" value="<?php echo $_GET["input_name"]?>" />
190        <input type="hidden" name="type" value="<?php echo $_GET["type"]?>" />
191</form>
192</body>
193</html>
Note: See TracBrowser for help on using the browser.