Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> Problem uploadifive
MiQss
post 1.07.2014, 15:59:28
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Witam, mam problem z skryptem PHP do wgrywania plików na serwer. Skrypt działa, pliki się wgrywają, jest napisane complete - ale. Pliki po wysłaniu lecą gdzieś w kosmos nie znajdują się w wyznaczonym katalogu /uploads/. Dzięki za pomoc z góry!

index.php
  1. <title>UploadiFive Test</title>
  2. <script src="jquery.min.js" type="text/javascript"></script>
  3. <script src="jquery.uploadifive.min.js" type="text/javascript"></script>
  4. <link rel="stylesheet" type="text/css" href="uploadifive.css">
  5. <style type="text/css">
  6. body {
  7. font: 13px Arial, Helvetica, Sans-serif;
  8. }
  9. .uploadifive-button {
  10. float: left;
  11. margin-right: 10px;
  12. }
  13. #queue {
  14. border: 1px solid #E5E5E5;
  15. height: 177px;
  16. overflow: auto;
  17. margin-bottom: 10px;
  18. padding: 0 3px 3px;
  19. width: 300px;
  20. }
  21. </style>
  22. </head>
  23.  
  24. <body>
  25. <h1>UploadiFive Demo</h1>
  26. <form>
  27. <div id="queue"></div>
  28. <input id="file_upload" name="file_upload" type="file" multiple="true">
  29. <a style="position: relative; top: 8px;" href="java script:$('#file_upload').uploadifive('upload')">Upload Files</a>
  30. </form>
  31.  
  32. <script type="text/javascript">
  33. <?php $timestamp = time();?>
  34. $(function() {
  35. $('#file_upload').uploadifive({
  36. 'auto' : false,
  37. 'checkScript' : 'check-exists.php',
  38. 'formData' : {
  39. 'timestamp' : '<?php echo $timestamp;?>',
  40. 'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
  41. },
  42. 'queueID' : 'queue',
  43. 'uploadScript' : 'uploadifive.php',
  44. 'onUploadComplete' : function(file, data) { console.log(data); }
  45. });
  46. });
  47. </script>
  48. </body>
  49. </html>


oraz uploadifive.php

  1. <?php
  2. /*
  3. UploadiFive
  4. Copyright (c) 2012 Reactive Apps, Ronnie Garcia
  5. */
  6.  
  7. // Set the uplaod directory
  8. $uploadDir = '/uploads';
  9.  
  10. // Set the allowed file extensions
  11. $fileTypes = array('jpg','JPG','jpeg','JPEG','gif','GIF','png','PNG'); // Allowed file extensions
  12.  
  13. $verifyToken = md5('unique_salt' . $_POST['timestamp']);
  14.  
  15. if (!empty($_FILES) /* && $_POST['token'] == $verifyToken */) {
  16. $tempFile = $_FILES['Filedata']['tmp_name'];
  17. $uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
  18. $targetFile = $uploadDir . $_FILES['Filedata']['name'];
  19.  
  20. // Validate the filetype
  21. $fileParts = pathinfo($_FILES['Filedata']['name']);
  22. if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
  23.  
  24. // Save the file
  25. move_uploaded_file($tempFile, $targetFile);
  26. echo 1;
  27.  
  28. } else {
  29.  
  30. // The file type wasn't allowed
  31. echo 'Invalid file type.';
  32.  
  33. }
  34. }
  35. ?>
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 16:14:01
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


  1. $uploadDir = '/uploads';

Sprawdź czy nie wrzuciło plików, w któryś z katalogów wyżej od tego, w którym testujesz.
W razie czego ustaw na ścieżkę względną.

Ten post edytował trueblue 1.07.2014, 16:14:32


--------------------
Go to the top of the page
+Quote Post
SmokAnalog
post 1.07.2014, 16:21:42
Post #3





Grupa: Zarejestrowani
Postów: 1 707
Pomógł: 266
Dołączył: 3.07.2012
Skąd: Poznań

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


Zrób skrypt:
  1. echo $_SERVER['DOCUMENT_ROOT'];


I odpal go w konsoli smile.gif
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 16:31:03
Post #4





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


1. nie działa

jak odpalić w konsoli?
Go to the top of the page
+Quote Post
SmokAnalog
post 1.07.2014, 16:33:01
Post #5





Grupa: Zarejestrowani
Postów: 1 707
Pomógł: 266
Dołączył: 3.07.2012
Skąd: Poznań

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


Przepraszam, pomieszało mi się z innym wątkiem biggrin.gif

Sprawdź co zwraca move_uploaded_file.
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 16:42:06
Post #6





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Nie wiem czy dobrze robię, ale zwraca 1
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 16:50:06
Post #7





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


A jak wygląda u Ciebie teraz $uploadDir ?


--------------------
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 16:58:29
Post #8





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Nie za bardzo rozumiem. Nowy jestem...
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 17:03:01
Post #9





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Zacytowałem wyżej linijkę kodu, która być może powoduje błąd (nie różni się niczym od tego co podałeś Ty).
Proponowałem abyś sprawdził czy nie wrzuca pliku, w któryś katalog wyżej oraz zmienił ścieżkę na względną.
Wiesz jak wyglądają ścieżki względne?
http://matipl.pl/2007/04/12/sciezki-w-php/


--------------------
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 17:08:32
Post #10





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Wygląda to u mnie tak:

$uploadDir = './home/schwarzd/public_html/panel/uploads/';

z czego schwarzd to login
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 17:11:15
Post #11





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Taka na pewno być nie może.
Zmień na:
$uploadDir = './uploads/';
jeśli plik uploadifive.php jest w katalogu /panel


--------------------
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 17:13:04
Post #12





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Taka ścieżka także nie pomaga.
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 17:15:42
Post #13





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


W jakim katalogu masz plik uploadifive.php?


--------------------
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 17:20:08
Post #14





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Mam w subdomenie, czyli /public_html/panel/
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 17:21:58
Post #15





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Zakomentuj linię 17 w tym skrypcie i pozostaw:
$uploadDir = './uploads/';


--------------------
Go to the top of the page
+Quote Post
SmokAnalog
post 1.07.2014, 17:30:12
Post #16





Grupa: Zarejestrowani
Postów: 1 707
Pomógł: 266
Dołączył: 3.07.2012
Skąd: Poznań

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


Powodem może też być brak folderu do plików tymczasowych, miałem ten problem nieraz na serwerach home.pl. Musiałem utworzyć ręcznie folder tmp.
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 17:31:37
Post #17





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


Dzięki!!! Jesteś wielki! A mógłbym wiedzieć cóż to było?

I jeszcze jedna sprawa o której bym zapomniał. Wiesz może jak usnąć z tego skryptu ograniczenie rozszerzenia, tak aby można było wgrywać wszystkie pliki?
Go to the top of the page
+Quote Post
trueblue
post 1.07.2014, 17:37:15
Post #18





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Po prostu każda wcześniej ustawiona ścieżka do katalogu (poprzez zmienną $uploadDir) wraz ze zmienną $_SERVER['DOCUMENT_ROOT'] kierowała na nieprawidłową lokalizację.

  1. <?php
  2. /*
  3. UploadiFive
  4. Copyright (c) 2012 Reactive Apps, Ronnie Garcia
  5. */
  6.  
  7. // Set the uplaod directory
  8. $uploadDir = './uploads';
  9.  
  10.  
  11. $verifyToken = md5('unique_salt' . $_POST['timestamp']);
  12.  
  13. if (!empty($_FILES) /* && $_POST['token'] == $verifyToken */) {
  14. $tempFile = $_FILES['Filedata']['tmp_name'];
  15. $targetFile = $uploadDir . $_FILES['Filedata']['name'];
  16.  
  17. // Save the file
  18. move_uploaded_file($tempFile, $targetFile);
  19. echo 1;
  20.  
  21. }
  22. ?>


--------------------
Go to the top of the page
+Quote Post
MiQss
post 1.07.2014, 17:41:25
Post #19





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 27.06.2014

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


To nie działa, tzn działa tylko tak jak wtedy - jest completed ale plików nie ma:/
Go to the top of the page
+Quote Post
SmokAnalog
post 1.07.2014, 17:42:55
Post #20





Grupa: Zarejestrowani
Postów: 1 707
Pomógł: 266
Dołączył: 3.07.2012
Skąd: Poznań

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


Tu to masz:
  1. $fileTypes = array('jpg','JPG','jpeg','JPEG','gif','GIF','png','PNG'); // Allowed file extensions


Dopisz co chcesz po przecinku w apostrofach.
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 15.07.2025 - 21:53