Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [AJAX][PHP]zagnieżdżenie pliku php do index.php
Forum PHP.pl > Forum > Przedszkole
hottt
Witam, to mój pierwszy post i nie ukrywam, że temat php jest dla mnie prawie czarną magią.
Posiadam własny serwer plików gdzie strona startowa to taka zawartość:
  1. <?php
  2.  
  3. // Tastydir is copyright Vlad Harbuz (vladh.net)
  4.  
  5. define('TASTYDIR_VERSION','1.2');
  6. define('TASTYDIR_SUBVERSION','1252');
  7.  
  8.  
  9. if(!file_exists('_tastydir/settings.php')){
  10. require_once('_tastydir/install.php');
  11. die();
  12. }
  13.  
  14. require_once '_tastydir/common.php';
  15. require_once '_tastydir/settings.php';
  16.  
  17. //////////////////////////
  18. // authentication
  19. ////////
  20. $auth['loggedin']=false;
  21.  
  22. if($auth['use']){
  23.  
  24. // login action
  25. if(isset($_POST['action']) && $_POST['action']=='login' && !empty($_POST['pw'])){
  26. if(sha1($_POST['pw'])==$auth['pass']){
  27. // set cookie for 24 hours
  28. setcookie('tastydir_auth',sha1($auth['pass']),time()+86400);
  29. header('Location: index.php');
  30. }
  31. }
  32.  
  33. // logout action
  34. if(isset($_GET['action']) && $_GET['action']=='logout'){
  35. setcookie('tastydir_auth','',time()-86400);
  36. header('Location: index.php');
  37. }
  38.  
  39. // check if logged in
  40. if(!empty($_COOKIE['tastydir_auth']) && $_COOKIE['tastydir_auth']==sha1($auth['pass'])){
  41. $auth['loggedin']=true;
  42. }
  43. }else{
  44. $auth['loggedin']=true;
  45. }
  46.  
  47. ?>
  48. <!doctype html>
  49. <html>
  50. <head>
  51. <title>tastydir</title>
  52. <link rel="stylesheet" href="_tastydir/style.css">
  53. </head>
  54. <body>
  55. <div id="everything" class="fluid">
  56. <div id="header">
  57. <h1>tastydir</h1>
  58. </div>
  59. <div id="nav" class="rounded_top clearfix">
  60. <div id="navnav">
  61. <button class="icon" onClick="history.go(-1);">&laquo;</button>
  62. <button class="icon" onClick="updateFiles(document.location.hash.substr(1));"><img src="_tastydir/images/arrow_refresh.png" alt="Refresh" title="Refresh"></button>
  63. <button onclick="document.location='#';">Home</button>
  64. <?php if($win){ ?>
  65. <div id="letters">
  66. <button class="icon">
  67. <img src="_tastydir/images/loading.gif">
  68. </button>
  69. </div>
  70. <?php } ?>
  71. </div>
  72. <?php if($auth['use']){ ?>
  73. <div id="meta">
  74. <div class="item"><a rel="tipsy" id="topinfo"><img src="_tastydir/images/information.png" alt="Info"></a></div>
  75. <div class="sep"></div>
  76. <?php
  77. if($auth['loggedin']){ ?>
  78. <div class="item" id="login"><a href="index.php?action=logout">Log out <img src="_tastydir/images/door_out.png" title="Log out" alt="Log out"></a></div>
  79. <?php }else{ ?>
  80. <div class="item" id="login"><a href="java script:;" onClick="replaceLogin();">Log in <img src="_tastydir/images/user_go.png" title="Log in" alt="Log in"></a></div>
  81. <?php } ?>
  82. </div>
  83. <?php } ?>
  84. </div>
  85. <div id="path" class="clearfix">
  86.  
  87. </div>
  88. <div id="body">
  89. <div id="files_outer">
  90. <table id="files_table">
  91. <thead id="files_head">
  92. <tr>
  93. <th style="width:55%;">Name</th>
  94. <th style="width:15%;">Size</th>
  95. <th style="width:15%;">Permissions</th>
  96. <th style="width:15%;">Actions</th>
  97. </tr>
  98. </thead>
  99. <tbody id="files">
  100. </tbody>
  101. </table>
  102. </div>
  103. <div class="modal" id="loading_modal">
  104. <img src="_tastydir/images/loading.gif">
  105. </div>
  106. <div class="modal" id="editfile_modal">
  107. </div>
  108. </div>
  109. <div id="bottombar" class="clearfix">
  110. <div id="bottombar_l">Navigate to the folder you want to copy or move <span id="copyname"></span> to, then use the buttons on the right.</div>
  111. <div id="bottombar_r">
  112. <a href="java script:;" onClick="closeCopyBar();">Cancel <img src="_tastydir/images/cancel.png" alt="Cancel" title="Cancel"></a>
  113. <span style="padding:0 10px;">&nbsp;</span> <!-- ok so this is hacky -->
  114. <a href="java script:;" onClick="copyFileAttempt(cdir,false);">Copy here <img src="_tastydir/images/folder_go.png" alt="Cancel" title="Cancel"></a>
  115. <span style="padding:0 10px;">&nbsp;</span> <!-- ok so this is hacky -->
  116. <a href="java script:;" onClick="copyFileAttempt(cdir,true);">Move here <img src="_tastydir/images/folder_go.png" alt="Cancel" title="Cancel"></a>
  117. </div>
  118. </div>
  119. <div id="footer" class="rounded_bottom clearfix">
  120. <div id="makefiles">
  121. <div class="makefile"><a href="java script:;" onClick="createFileDialog(cdir);">Create file <img src="_tastydir/images/page_white_add.png" alt="Create file" title="Create file"></a></div>
  122. <div class="sep"></div>
  123. <div class="makefile"><a href="java script:;" onClick="createFolderDialog(cdir);">Create folder <img src="_tastydir/images/folder_add.png" alt="Create folder" title="Create folder"></a></div>
  124. </div>
  125. <div id="uploadfile">
  126. <div id="uploadform">
  127. <div id="uploadform_progress"><img src="_tastydir/images/loading.gif"></div>
  128. <div id="uploadform_really">
  129. <form enctype="multipart/form-data" action="_tastydir/do.php" method="POST" onsubmit="return startUpload();" target="hacky_iframe" id="uploadform_seriously">
  130. <input name="file" type="file" id="upload_finput">
  131. <input type="submit" value="Upload">
  132. </form>
  133. </div>
  134. <iframe id="hacky_iframe" name="hacky_iframe" src="#"></iframe>
  135. </div>
  136. <div id="uploadtext">
  137. <a href="java script:;" onClick="showUploadForm();"><span id="uploadtext_really">Upload file</span> <img src="_tastydir/images/page_white_get.png" alt="Upload file" title="Upload file"></a>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <script>
  143. var t_dn='<?php echo $t_dn; ?>';
  144. var loggedin=<?php echo $auth['loggedin'] ? 'true' : 'false'; ?>;
  145. var t_version='<?php echo TASTYDIR_VERSION; ?>';
  146. var t_subversion=<?php echo TASTYDIR_SUBVERSION; ?>;
  147. var t_fname_blacklist='<?php foreach($fname_blacklist as $key=>$ff){ if($key!=(count($fname_blacklist)-1)){ if($key!=0){echo ' ';} echo str_replace('\\','\\\\',$ff); } } ?>';
  148. var t_metainfo = {
  149. user: '<?php echo $t_curruser; ?>'
  150. };
  151. var t_switchlayout=false;
  152. var t_path='<?php echo $path; ?>';
  153. </script>
  154. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  155. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
  156. <script src="_tastydir/js/jquery.ba-hashchange.min.js"></script>
  157. <script src="_tastydir/js/jquery.tipsy.js"></script>
  158. <script src="_tastydir/js/site.js"></script>
  159. </body>
  160. </html>

Problem w tym, że upload z tego skrytpu nie ma opcji multiuploadu i znalazłem darmowy skrypt, ale nie bardzo wiem jak go wkleić do indexu na górze, aby działał na stronie głównej.
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>UploadiFive Test</title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  7. <script src="jquery.uploadify.min.js" type="text/javascript"></script>
  8. <link rel="stylesheet" type="text/css" href="uploadify.css">
  9. <style type="text/css">
  10. body {
  11. font: 13px Arial, Helvetica, Sans-serif;
  12. }
  13. </style>
  14. </head>
  15.  
  16. <body>
  17. <h1>Uploadify Demo</h1>
  18. <form>
  19. <div id="queue"></div>
  20. <input id="file_upload" name="file_upload" type="file" multiple="true">
  21. </form>
  22.  
  23. <script type="text/javascript">
  24. <?php $timestamp = time();?>
  25. $(function() {
  26. $('#file_upload').uploadify({
  27. 'formData' : {
  28. 'timestamp' : '<?php echo $timestamp;?>',
  29. 'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
  30. },
  31. 'swf' : 'uploadify.swf',
  32. 'uploader' : 'uploadify.php'
  33. });
  34. });
  35. </script>
  36. </body>
  37. </html>

Za wszelką pomoc dziękuję.
gitbejbe
też nie wiem jak go wkleić... Może było by łatwiej gdyby nie ten "kod" ; )

Jeśli php to dla Ciebie czarna magia, to nie oczekuj, ze wklejanie na ciemno gotowców w czymś Ci pomoże.

Na poczatek przeanalizuj ten kod:
  1. <form method="post" enctype="multipart/form-data" >
  2. <input type="file" name="file[]" multiple id="file"/>
  3. <input type="submit" name="ok" />
  4. </form>

  1. <?php
  2. if(isset($_POST['ok']))
  3. foreach ($_FILES['file']['name'] as $filename) {
  4. echo $filename.'<br/>';
  5. }
  6. ?>


Musisz zacząć sam pisać skrypty, bo nigdy nic dobrze nie zrobisz...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.