Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Błąd: Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp
seslo
post 9.04.2013, 09:00:20
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


Witam
Nie wiem co mam zrobić, wyskakują mi 2 błędy:


Warning: move_uploaded_file(C:\Users\admin\Desktop/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/u407141732/public_html/czesci_komp.php on line 19

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpWjNM1Y' to 'C:\Users\admin\Desktop/' in /home/u407141732/public_html/czesci_komp.php on line 19

kod:

?<?php

$message = null;

$allowed_extensions = array('csv');

$upload_path = '\\BASTEK\Users\admin\Desktop';


if (!empty($_FILES['file'])) {

if ($_FILES['file']['error'] == 0) {

$file = explode(".", $_FILES['file']['name']);
$extension = array_pop($file);

if (in_array($extension, $allowed_extensions)) {

if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) {

if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) {

......



proszę o pomoc!
Go to the top of the page
+Quote Post
Michael2318
post 9.04.2013, 09:12:02
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


Masz znacznik php to zacznij go używać.
Go to the top of the page
+Quote Post
seslo
post 9.04.2013, 09:53:07
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


Może mi ktoś to wytłumaczyć i powiedzieć jak to rozwiązać ?
Dziękuje.
Go to the top of the page
+Quote Post
Michael2318
post 9.04.2013, 18:04:05
Post #4





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


A może wykażesz minimum inicjatywy i Ty ze swojej strony i wkleisz ten kod jak należy...?
Go to the top of the page
+Quote Post
seslo
post 10.04.2013, 06:45:49
Post #5





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


To jest kod. Na serwerze lokalnym działa dobrze. Natomiast na zewnętrznym serwerze www nie działa.
I to są te dwa błędy:



Warning: move_uploaded_file(C:\Users\admin\Desktop/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/u407141732/public_html/czesci_komp.php on line 19

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpwPx6Mj' to 'C:\Users\admin\Desktop/' in /home/u407141732/public_html/czesci_komp.php on line 19


  1. <?php
  2.  
  3. $message = null;
  4.  
  5. $allowed_extensions = array('csv');
  6.  
  7. $upload_path = '\\BASTEK\Users\admin\Desktop';
  8.  
  9.  
  10. if (!empty($_FILES['file'])) {
  11.  
  12. if ($_FILES['file']['error'] == 0) {
  13.  
  14. $file = explode(".", $_FILES['file']['name']);
  15. $extension = array_pop($file);
  16.  
  17. if (in_array($extension, $allowed_extensions)) {
  18.  
  19. if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) {
  20.  
  21. if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) {
  22.  
  23. $keys = array();
  24. $out = array();
  25.  
  26. $insert = array();
  27.  
  28. $line = 1;
  29.  
  30. while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) {
  31.  
  32. foreach($row as $key => $value) {
  33. if ($line === 1) {
  34. $keys[$key] = $value;
  35. } else {
  36. $out[$line][$key] = $value;
  37.  
  38. }
  39. }
  40.  
  41. $line++;
  42.  
  43. }
  44.  
  45. fclose($handle);
  46.  
  47. if (!empty($keys) && !empty($out)) {
  48.  
  49. $db = new PDO('mysql:mysql.er.plt;dbname=u41732_s', 'u407141', 'Pojt1');
  50. $db->exec("SET CHARACTER SET utf8");
  51.  
  52. $sql = "DELETE FROM `sprzet`";
  53. $db->exec($sql);
  54.  
  55. $sql = "ALTER TABLE `sprzet` AUTO_INCREMENT = 0";
  56. $db->exec($sql);
  57.  
  58. foreach($out as $key => $value) {
  59.  
  60. $sql = "INSERT INTO `sprzet` (`";
  61. $sql .= implode("`, `", $keys);
  62. $sql .= "`) VALUES (";
  63. $sql .= implode(", ", array_fill(0, count($keys), "?"));
  64. $sql .= ")";
  65. $statement = $db->prepare($sql);
  66. $statement->execute($value);
  67.  
  68. }
  69.  
  70. $message = '<span class="green">Plik załadował się pomyślnie !</span>';
  71.  
  72. }
  73.  
  74. }
  75.  
  76. }
  77.  
  78. } else {
  79. $message = '<span class="red">Dozwolone tylko pliki .csv</span>';
  80. }
  81.  
  82. } else {
  83. $message = '<span class="red">Wystąpił problem z plikiem</span>';
  84. }
  85.  
  86. }
  87.  
  88. ?>
Go to the top of the page
+Quote Post
Michael2318
post 10.04.2013, 07:00:53
Post #6





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


Jak na moje to taka ścieżka w ogóle nie istnieje:
  1. $upload_path = '\\BASTEK\Users\admin\Desktop';
Go to the top of the page
+Quote Post
seslo
post 10.04.2013, 08:11:19
Post #7





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


powinno być coś takiego ?

  1. $upload_path = 'C:\Users\admin\Desktop';


?
Go to the top of the page
+Quote Post
matiit
post 10.04.2013, 08:22:58
Post #8





Grupa: Zarejestrowani
Postów: 365
Pomógł: 70
Dołączył: 5.04.2009

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


A serwer stoi na windowsie czy Linuksie?
Raczej
  1. /home/user/public_html/domain/uploaded
jeśli to hosting dzielony na wielu userów.
Na dedyku czy VPS jeszcze inaczej będzie (ale podobnie).
Go to the top of the page
+Quote Post
seslo
post 10.04.2013, 08:51:46
Post #9





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


Jest to linux serwer
Go to the top of the page
+Quote Post
matiit
post 10.04.2013, 08:55:13
Post #10





Grupa: Zarejestrowani
Postów: 365
Pomógł: 70
Dołączył: 5.04.2009

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


Jeśli nie działasz na żadnym frameworku to:

powiedzmy że masz taką strukturę:

myapp/upload.php
upload/

Aby odwołać się z pliku upload.php do katalogu upload/ robisz tak:
Kod
../upload/


../ - oznacza "katalog wyżej".
../../ - dwa katalogi wyżej
./ - bieżący katalog.

Pamiętaj że w Linuksie używa się '/' a nie '\'
Go to the top of the page
+Quote Post
seslo
post 10.04.2013, 10:24:33
Post #11





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


matiit zrobiłem tak jak napisałeś i wciąż mam te dwa błędy:


Warning: move_uploaded_file(C:\Users\admin\Desktop/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/u407141732/public_html/czesci_komp.php on line 19

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpdnjo7e' to 'C:\Users\admin\Desktop/' in /home/u407141732/public_html/czesci_komp.php on line 19

Go to the top of the page
+Quote Post
matiit
post 10.04.2013, 10:30:50
Post #12





Grupa: Zarejestrowani
Postów: 365
Pomógł: 70
Dołączył: 5.04.2009

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


Przecież nadal masz ustawioną windowsową ścieżke z Twojego systemu..
Go to the top of the page
+Quote Post
seslo
post 10.04.2013, 11:44:52
Post #13





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 9.04.2013

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


kod jest na serwerze linuks. Natomiast plik pobieram ze swojego pulpitu na komputerze.
Go to the top of the page
+Quote Post
matiit
post 10.04.2013, 11:56:09
Post #14





Grupa: Zarejestrowani
Postów: 365
Pomógł: 70
Dołączył: 5.04.2009

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


Ale jak coś uploadujesz to przecież najpierw plik jest kopiowany do /tmp ('/tmp/phpdnjo7e' w Twoim przypadku), a potem z /tmp kopiujesz go gdzieś do stałego katalogu na serwerze.

Nie wiem jak to wytłumaczyć, ale robisz to źle.

http://www.php.rk.edu.pl/w/p/wysylanie-pliku-na-serwer/ chyba tu jest to wyjaśnione.
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 Wersja Lo-Fi Aktualny czas: 5.06.2025 - 20:13