Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wrzucanie plików na dropbox - błąd
janmaniek
post 12.02.2014, 16:24:12
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 12.02.2014

Ostrzeżenie: (0%)
-----


Witam, znalazłem na tej stronie http://code.tutsplus.com/tutorials/simple-...older--wp-23632 skrypt, dzięki któremu można wrzucać pliki na dropbox. Tylko, że po uruchomieniu wyskakuje błąd "Fatal error: Call to undefined function add_action() in dbouploader.php on line 104". Ma ktoś pomysł jak to naprawić questionmark.gif Z góry dziękuje za pomoc.

Tutaj wrzucam kod źródłowy :
dbouploader.php
  1. <?php
  2. /*
  3. Plugin Name: DboUploader - Dropbox upload
  4. Plugin URI: <a href="http://www.webania.net/dbouploader/" target="_blank">http://www.webania.net/dbouploader/</a>
  5. Description: Upload to Dropbox
  6. Version: 1.0
  7. Author: Elvin Haci
  8. Author URI: <a href="http://www.webania.net" target="_blank">http://www.webania.net</a>
  9. License: GPL2
  10. */
  11. /* Copyright 2011, Elvin Haci (email : elvinhaci@hotmail.com)
  12.  
  13.   This program is free software; you can redistribute it and/or modify
  14.   it under the terms of the GNU General Public License, version 2, as
  15.   published by the Free Software Foundation.
  16.  
  17.   This program is distributed in the hope that it will be useful,
  18.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20.   GNU General Public License for more details.
  21.  
  22.   You should have received a copy of the GNU General Public License
  23.   along with this program; if not, write to the Free Software
  24.   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26.  
  27. function dbouploader($content = '') {
  28.  
  29. if (is_user_logged_in()) add_shortcode('dbouploader', 'shortcoder');
  30. else add_shortcode('dbouploader', 'notloggedin');
  31. return $content;
  32. }
  33.  
  34. function notloggedin($atts,$content = '') {
  35. return 'You must be logged in!';
  36. }
  37.  
  38.  
  39. function shortcoder($atts,$content = '') {
  40.  
  41. //////////////////
  42. define("dboconf","1");
  43. include(WP_PLUGIN_DIR . "/" . plugin_basename(dirname(__FILE__))."/config.php");
  44.  
  45. if ($_POST) {
  46.  
  47. include(WP_PLUGIN_DIR . "/" . plugin_basename(dirname(__FILE__))."/DropboxUploader.php");
  48.  
  49.  
  50. try {
  51. // Rename uploaded file to reflect original name
  52. if ($_FILES['file']['error'] !== UPLOAD_ERR_OK)
  53. throw new Exception('File was not successfully uploaded from your computer.');
  54.  
  55. if( !in_array($_FILES["file"]["type"],$supported_types) or $_FILES["file"]["size"] > $size_limit)
  56. throw new Exception('File size is too large or file type is not supported.');
  57.  
  58.  
  59. $tmpDir = uniqid('/tmp/DropboxUploader-');
  60. if (!mkdir($tmpDir))
  61. throw new Exception('Cannot create temporary directory!');
  62.  
  63. if ($_FILES['file']['name'] === "")
  64. throw new Exception('File name not supplied by the browser.');
  65. global $current_user;
  66. get_currentuserinfo();
  67.  
  68. $tmpFile = $tmpDir.'/'.str_replace("/\0", '_', $current_user->user_email.'_'.$_FILES['file']['name']);
  69. if (!move_uploaded_file($_FILES['file']['tmp_name'], $tmpFile))
  70. throw new Exception('Cannot rename uploaded file!');
  71.  
  72. // Enter your Dropbox account credentials here
  73. $uploader = new DropboxUploader($dropbox_email, $dropbox_password);
  74. $uploader->upload($tmpFile, $_POST['dest']);
  75.  
  76. return '<span style="color: green;font-weight:bold;margin-left:0px;">File successfully uploaded. Thank you!</span>';
  77. } catch(Exception $e) {
  78. return '<span style="color: red;font-weight:bold;margin-left:0px;">Error: ' . htmlspecialchars($e->getMessage()) . '</span>';
  79. }
  80.  
  81. // Clean up
  82. if (isset($tmpFile) && file_exists($tmpFile))
  83. unlink($tmpFile);
  84.  
  85. if (isset($tmpDir) && file_exists($tmpDir))
  86. rmdir($tmpDir);
  87.  
  88. }
  89. else {
  90. return '
  91. <div class="box" align="center">
  92. <h1>Dropbox Uploader Demo<br>
  93. </h1>
  94. <form method="POST" enctype="multipart/form-data">
  95. <input type="file" name="file" /><br><br>
  96. <input type="submit" value="Upload your file!" />
  97. <input style="display:none" type="text" name="dest" value="'.$dropbox_folder.'" />
  98. </div> ';
  99. }
  100. ////////////////
  101. }
  102.  
  103.  
  104. add_action('the_content', 'dbouploader');
  105. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 23.06.2025 - 15:20