Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem przy wysyłaniu większych plików (phUploader)
qwert89
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 16.04.2010

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


Witam, chciałbym korzystać z tego skryptu jednak mimo powiększenia limitu dot. wielkości pliku największy plik jaki udało mi się wysłać miał ok. 1.3MB. Przy większych wyrzuca błąd: REASON: General upload failure. Prosiłbym też o ogólną ocenę tego skryptu.
Skrypt (usunąłem info od autora i css gdyż nie chciało przyjąć wiadomości):

  1. // Max size PER file in KB
  2. $max_file_size="1000000000000000";
  3.  
  4. // Max size for all files COMBINED in KB
  5. $max_combined_size="10000000000000000";
  6.  
  7. //Maximum file uploades at one time
  8. $file_uploads="4";
  9.  
  10. //The name of your website
  11. $websitename="Your site name";
  12.  
  13. // Full browser accessable URL to where files are accessed. With trailing slash.
  14. $full_url="http://YOUR_SITE/uploads/";
  15.  
  16. // Path to store files on your server If this fails use $fullpath below. With trailing slash.
  17. $folder="./uploads/";
  18.  
  19. // Use random file names? true=yes (recommended), false=use original file name.
  20. // Random names will help prevent files being denied because a file with that name already exists.
  21. $random_name=true;
  22.  
  23. // Types of files that are acceptiable for uploading. Keep the array structure.
  24. $allow_types=array("jpg","gif","png","zip","rar","txt","doc");
  25.  
  26. // Only use this variable if you wish to use full server paths. Otherwise leave this empty. With trailing slash.
  27. $fullpath="";
  28.  
  29. //Use this only if you want to password protect your upload form.
  30. $password="";
  31.  
  32. /*
  33. //================================================================================
  34. * ! ATTENTION !
  35. //================================================================================
  36. :- Please read the above FAQ before giving up or emailing me. It may sort out your problems!
  37. */
  38.  
  39. // Max size PER file in KB
  40. $max_file_size="512";
  41.  
  42. // Max size for all files COMBINED in KB
  43. $max_combined_size="2048";
  44.  
  45. //Maximum file uploades at one time
  46. $file_uploads="4";
  47.  
  48. //The name of your website
  49. $websitename="Your site name";
  50.  
  51. // Full browser accessable URL to where files are accessed. With trailing slash.
  52. $full_url="http://YOUR_SITE/uploads/";
  53.  
  54. // Path to store files on your server If this fails use $fullpath below. With trailing slash.
  55. $folder="./uploads/";
  56.  
  57. // Use random file names? true=yes (recommended), false=use original file name.
  58. // Random names will help prevent files being denied because a file with that name already exists.
  59. $random_name=true;
  60.  
  61. // Types of files that are acceptiable for uploading. Keep the array structure.
  62. $allow_types=array("jpg","gif","png","zip","rar","txt","doc");
  63.  
  64. // Only use this variable if you wish to use full server paths. Otherwise leave this empty. With trailing slash.
  65. $fullpath="";
  66.  
  67. //Use this only if you want to password protect your upload form.
  68. $password="";
  69.  
  70. /*
  71. //================================================================================
  72. * ! ATTENTION !
  73. //================================================================================
  74. : Don't edit below this line.
  75. */
  76.  
  77. // Initialize variables
  78. $password_hash=md5($password);
  79. $error="";
  80. $success="";
  81. $display_message="";
  82. $file_ext=array();
  83. $password_form="";
  84.  
  85. // Function to get the extension a file.
  86. function get_ext($key) {
  87. $key=strtolower(substr(strrchr($key, "."), 1));
  88. $key=str_replace("jpeg","jpg",$key);
  89. return $key;
  90. }
  91.  
  92. // Filename security cleaning. Do not modify.
  93. function cln_file_name($string) {
  94. $cln_filename_find=array("/\.[^\.]+$/", "/[^\d\w\s-]/", "/\s\s+/", "/[-]+/", "/[_]+/");
  95. $cln_filename_repl=array("", ""," ", "-", "_");
  96. $string=preg_replace($cln_filename_find, $cln_filename_repl, $string);
  97. return trim($string);
  98. }
  99.  
  100. // If a password is set, they must login to upload files.
  101. If($password) {
  102.  
  103. //Verify the credentials.
  104. If($_POST['verify_password']==true) {
  105. If(md5($_POST['check_password'])==$password_hash) {
  106. setcookie("phUploader",$password_hash);
  107. sleep(1); //seems to help some people.
  108. header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
  109. exit;
  110. }
  111. }
  112.  
  113. //Show the authentication form
  114. If($_COOKIE['phUploader']!=$password_hash) {
  115. $password_form="<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
  116. $password_form.="<table align=\"center\" class=\"table\">\n";
  117. $password_form.="<tr>\n";
  118. $password_form.="<td width=\"100%\" class=\"table_header\" colspan=\"2\">Password Required</td>\n";
  119. $password_form.="</tr>\n";
  120. $password_form.="<tr>\n";
  121. $password_form.="<td width=\"35%\" class=\"table_body\">Enter Password:</td>\n";
  122. $password_form.="<td width=\"65%\" class=\"table_body\"><input type=\"password\" name=\"check_password\" /></td>\n";
  123. $password_form.="</tr>\n";
  124. $password_form.="<td colspan=\"2\" align=\"center\" class=\"table_body\">\n";
  125. $password_form.="<input type=\"hidden\" name=\"verify_password\" value=\"true\">\n";
  126. $password_form.="<input type=\"submit\" value=\" Verify Password \" />\n";
  127. $password_form.="</td>\n";
  128. $password_form.="</tr>\n";
  129. $password_form.="</table>\n";
  130. $password_form.="</form>\n";
  131. }
  132.  
  133. } // If Password
  134.  
  135. // Dont allow submit if $password_form has been populated
  136. If(($_POST['submit']==true) AND ($password_form=="")) {
  137.  
  138. //Tally the size of all the files uploaded, check if it's over the ammount.
  139. If(array_sum($_FILES['file']['size']) > $max_combined_size*1024) {
  140.  
  141. $error.="<b>FAILED:</b> All Files <b>REASON:</b> Combined file size is to large.<br />";
  142.  
  143. // Loop though, verify and upload files.
  144. } Else {
  145.  
  146. // Loop through all the files.
  147. For($i=0; $i <= $file_uploads-1; $i++) {
  148.  
  149. // If a file actually exists in this key
  150. If($_FILES['file']['name'][$i]) {
  151.  
  152. //Get the file extension
  153. $file_ext[$i]=get_ext($_FILES['file']['name'][$i]);
  154.  
  155. // Randomize file names
  156. If($random_name){
  157. $file_name[$i]=time()+rand(0,100000);
  158. } Else {
  159. $file_name[$i]=cln_file_name($_FILES['file']['name'][$i]);
  160. }
  161.  
  162. // Check for blank file name
  163. If(str_replace(" ", "", $file_name[$i])=="") {
  164.  
  165. $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Blank file name detected.<br />";
  166.  
  167. //Check if the file type uploaded is a valid file type.
  168. } ElseIf(!in_array($file_ext[$i], $allow_types)) {
  169.  
  170. $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Invalide file type.<br />";
  171.  
  172. //Check the size of each file
  173. } Elseif($_FILES['file']['size'][$i] > ($max_file_size*1024)) {
  174.  
  175. $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File to large.<br />";
  176.  
  177. // Check if the file already exists on the server..
  178. } Elseif(file_exists($folder.$file_name[$i].".".$file_ext[$i])) {
  179.  
  180. $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File already exists.<br />";
  181.  
  182. } Else {
  183.  
  184. If(move_uploaded_file($_FILES['file']['tmp_name'][$i],$folder.$file_name[$i].".".$file_ext[$i])) {
  185.  
  186. $success.="<b>SUCCESS:</b> ".$_FILES['file']['name'][$i]."<br />";
  187. $success.="<b>URL:</b> <a href=\"".$full_url.$file_name[$i].".".$file_ext[$i]."\" target=\"_blank\">".$full_url.$file_name[$i].".".$file_ext[$i]."</a><br /><br />";
  188.  
  189. } Else {
  190. $error.="<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> General upload failure.<br />";
  191. }
  192.  
  193. }
  194.  
  195. } // If Files
  196.  
  197. } // For
  198.  
  199. } // Else Total Size
  200.  
  201. If(($error=="") AND ($success=="")) {
  202. $error.="<b>FAILED:</b> No files selected<br />";
  203. }
  204.  
  205. $display_message=$success.$error;
  206.  
  207. } // $_POST AND !$password_form
  208.  
  209. /*
  210. //================================================================================
  211. * Start the form layout
  212. //================================================================================
  213. :- Please know what your doing before editing below. Sorry for the stop and start php.. people requested that I use only html for the form..
  214. */
  215. ?>
  216. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  217. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  218. <head>
  219. <meta http-equiv="Content-Language" content="en-us" />
  220. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  221. <title><?php echo $websitename; ?> - Powered By phUploader</title>
  222.  
  223. <?
  224. If($password_form) {
  225.  
  226. Echo $password_form;
  227.  
  228. } Else {
  229. ?>
  230.  
  231. <form action="<?=$_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="phuploader">
  232. <table align="center" class="table">
  233. <tr>
  234. <td class="table_header" colspan="2"><b><?=$websitename;?></b> </td>
  235. </tr>
  236.  
  237. <?If($display_message){?>
  238. <tr>
  239. <td colspan="2" class="message">
  240. <br />
  241. <?=$display_message;?>
  242. <br />
  243. </td>
  244. </tr>
  245. <?}?>
  246.  
  247. <tr>
  248. <td colspan="2" class="upload_info">
  249. <b>Allowed Types:</b> <?=implode($allow_types, ", ");?><br />
  250. <b>Max size per file:</b> <?=$max_file_size?>kb.<br />
  251. <b>Max size for all files combined:</b> <?=$max_combined_size?>kb.<br />
  252. </td>
  253. </tr>
  254. <?For($i=0;$i <= $file_uploads-1;$i++) {?>
  255. <tr>
  256. <td class="table_body" width="20%"><b>Select File:</b> </td>
  257. <td class="table_body" width="80%"><input type="file" name="file[]" size="30" /></td>
  258. </tr>
  259. <?}?>
  260. <tr>
  261. <td colspan="2" align="center" class="table_footer">
  262. <input type="hidden" name="submit" value="true" />
  263. <input type="submit" value=" Upload File(s) " />  
  264. <input type="reset" name="reset" value=" Reset Form " onclick="window.location.reload(true);" />
  265. </td>
  266. </tr>
  267. </table>
  268. </form>
  269.  
  270. <?}//Please leave this here.. it really dosen't make people hate you or make your site look bad.. ?>
  271. <table class="table" style="border:0px;" align="center">
  272. <tr>
  273. <td><div class="copyright">?<a href="http://www.phphq.net/?script=phUploader" target="_blank" title="Uploader Powered By phUploader <www.phphq.net>">phUploader</a></div></td>
  274. </tr>
  275. </table>
  276. </body>
  277. </html>


Ten post edytował qwert89 18.04.2010, 19:02:46
Go to the top of the page
+Quote Post
moto0095
post
Post #2





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Ciekawie to wygląda, zaraz przetestuję smile.gif
Go to the top of the page
+Quote Post
tehaha
post
Post #3





Grupa: Zarejestrowani
Postów: 1 748
Pomógł: 388
Dołączył: 21.08.2009
Skąd: Gdynia

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


nie czytałem kodu, ale jeżeli skrypt bez problemu uploaduje małe pliki a z dużymi nie daje rady to problem może leżeć w serwerze, raz miałem do czynienia z serwerem gdzie nie było możliwości zmiany wartości limitów ani z poziomu php ani httaccess ani z panelu, po kontakcie z administracją serwera oznajmili mi że mają wewnętrzne ograniczenie na przesyłanie plików i nic na to nie poradzę, wtedy mój skrypt nie radził sobie z plikami większymi niż 2MB
Go to the top of the page
+Quote Post
qwert89
post
Post #4





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 16.04.2010

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


Coś może być na rzeczy bo już z drugim skryptem taki problem... Jedynie jak wrzucam przez klienta ftp to nie ma problemu. A jak mogę jeszcze spróbować to zmienić w pliku httaccess?
Autor na początku dodaje:
Kod
:- Q1: I always get an error that the files were not uploaded. IE: GENERAL ERROR
:-        1) Make sure you have CHMOD your "uploads" folder to 777 using your FTP client or similar. If you do
:-             not know how to do this ask your hosting provider.
:-        2) Make sure the uploads folder actually exists. This is the second most common mistake aside from
:-             improper permissions.
:-        3) If you are having problems uploading after you have chmod the uploads folder 777, try using the
:-             full server path in $fullpath below. If you do not know this ask your host.
:-        4) Make sure "file_uploads" is set to ON in php.ini
:-
:- Q2: The page takes long to load and then gives me a page cannot be displayed or a blank page.
:-        1) This is usually due to a low value in php.ini for "max_execution_time".
:-        2) A newer ini setting "max_file_uploads" in php 5.2.12 was added which may be limiting the number
            of simultaneous uploads.
:-        3) Your "upload_max_filesize" and "post_max_size" in php.ini might be set to low.


Ten post edytował qwert89 18.04.2010, 19:20:44
Go to the top of the page
+Quote Post
tehaha
post
Post #5





Grupa: Zarejestrowani
Postów: 1 748
Pomógł: 388
Dołączył: 21.08.2009
Skąd: Gdynia

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


do httaccess wrzucasz takie coś:
  1. php_value upload_max_filesize 100M
  2. php_value post_max_size 100M
  3. php_value max_execution_time 600
  4. php_value max_input_time 200


jeżeli masz możliwość to spróbuj na innym serwerze, zwłaszcza jeżeli testujesz to na jakimś darmowym
Go to the top of the page
+Quote Post
qwert89
post
Post #6





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 16.04.2010

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


Problem po stronie serwera (limit) bo na innym bez problemów działa. Dzięki za pomoc smile.gif
Go to the top of the page
+Quote Post

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 Aktualny czas: 19.08.2025 - 19:02