Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobieranie zmiennej z innej funkcji?
JamalBIG
post 24.01.2008, 19:01:14
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Witam

W jaki sposob zrobic aby funkcja jakasfunkcja() pobierala zmienna $nazwa ktora jest nad nia?

$nazwa = "nazwa";
function jakasfunkcja()
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 12)
b4x
post 24.01.2008, 19:05:51
Post #2





Grupa: Zarejestrowani
Postów: 658
Pomógł: 95
Dołączył: 20.12.2005
Skąd: N54,35° E18,63° (Gdańsk)

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


  1. <?php
  2. function jakasfunkcja($nazwa) {
  3. #polecenie do wykonania
  4. }
  5. ?>

Niewiem czy o to ci chodziło :-)

Ten post edytował b4x 24.01.2008, 19:06:14


--------------------
Go to the top of the page
+Quote Post
Cezar708
post 24.01.2008, 20:29:26
Post #3





Grupa: Zarejestrowani
Postów: 1 116
Pomógł: 119
Dołączył: 10.05.2005
Skąd: Poznań

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


być może o to Ci chodzi:
  1. <?php
  2. $nazwa = "wartość";
  3.  
  4. function jakas_funkcja(){
  5. global $nazwa;
  6. echo $nazwa;
  7. }
  8. ?>


nie jest to polecane, lepiej jak już tak chcesz robić to zrób tak:
  1. <?php
  2. class C{
  3. public static $nazwa;
  4. }
  5.  
  6. function jakas_funkcja(){
  7. echo C::$nazwa;
  8. }
  9. ?>
Go to the top of the page
+Quote Post
JamalBIG
post 24.01.2008, 20:39:35
Post #4





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Chodzi o to ze nie chce mi sie tworzyc miniaturka w tym kodzie i mysle ze jest to spowodowane tym, ze nie funkcja makeIcons_MergeCenter chce przeczytac zmiennych $cat, $r i $file (96 wiersz)

<?php
function makeIcons_MergeCenter($src, $dst, $dstx, $dsty){

// sprawdzanie rozszerzenia pliku
$allowedExtensions = 'jpg jpeg gif png'; // dozwolone

$name = explode(".", $src);
$currentExtensions = $name[count($name)-1];
$extensions = explode(" ", $allowedExtensions);

for($i=0; count($extensions)>$i; $i=$i+1){
if($extensions[$i]==$currentExtensions)
{ $extensionOK=1;
$fileExtension=$extensions[$i];
break; }
}

if($extensionOK){

$size = getImageSize($src);
$width = $size[0];
$height = $size[1];
// działanie tylko gdy oryginalny rozmiar pliku
// jest większy niż docelowy
if($width >= $dstx AND $height >= $dsty){
// ustalanie proporcji
$proportion_X = $width / $dstx;
$proportion_Y = $height / $dsty;

if($proportion_X > $proportion_Y ){
$proportion = $proportion_Y;
}else{
$proportion = $proportion_X ;
}
$target['width'] = $dstx * $proportion;
$target['height'] = $dsty * $proportion;

$original['diagonal_center'] =
round(sqrt(($width*$width)+($height*$height))/2);
$target['diagonal_center'] =
round(sqrt(($target['width']*$target['width'])+
($target['height']*$target['height']))/2);

$crop = round($original['diagonal_center'] - $target['diagonal_center']);

if($proportion_X < $proportion_Y ){
$target['x'] = 0;
$target['y'] = round((($height/2)*$crop)/$target['diagonal_center']);
}else{
$target['x'] = round((($width/2)*$crop)/$target['diagonal_center']);
$target['y'] = 0;
}
// tworzenie grafiki w zależności od rozszerzenia
if($fileExtension == "jpg" OR $fileExtension=='jpeg'){
$from = ImageCreateFromJpeg($src);
}elseif ($fileExtension == "gif"){
$from = ImageCreateFromGIF($src);
}elseif ($fileExtension == 'png'){
$from = imageCreateFromPNG($src);
}

$new = ImageCreateTrueColor ($dstx,$dsty);

imagecopyresampled ($new, $from, 0, 0, $target['x'],
$target['y'], $dstx, $dsty, $target['width'], $target['height']);
// zapisywanie nowo utworzonej grafiki
if($fileExtension == "jpg" OR $fileExtension == 'jpeg'){
imagejpeg($new, $dst, 70);
}elseif ($fileExtension == "gif"){
imagegif($new, $dst);
}elseif ($fileExtension == 'png'){
imagepng($new, $dst);
}
}
}
}

if ($cat == "c1") {
$cat = "videos";
} else {
$cat = "torrents";
}
$file = $_FILES['my_file']['name'];
$file = str_replace(' ', '', $file);
$r = explode('.',$file);
$r = $r[0];
$r = str_replace(' ', '', $r);

$filename = "downloads/$cat/$file";
if (file_exists($filename)) {
echo "Plik $filename juz istnieje $file";
} else {
mkdir ("downloads/$cat/$r");
if(isset($_FILES['my_file'])) {
if(is_uploaded_file($_FILES['my_file']['tmp_name'])) {
move_uploaded_file($_FILES['my_file']['tmp_name'], "downloads/$cat/$r/$file");
}
}
$pic = $_FILES['my_pic']['name'];
$pic = str_replace(' ', '', $pic);
$p = explode('.',$pic);
$p = $r[0];
$p = str_replace(' ', '', $p);
if(isset($_FILES['my_pic'])) {
if(is_uploaded_file($_FILES['my_pic']['tmp_name'])) {
move_uploaded_file($_FILES['my_pic']['tmp_name'], "downloads/$cat/$r/$pic");
}
}
echo "Plik downloads/$cat/$r/$file zostal dodany";
}

makeIcons_MergeCenter('downloads/$cat/$r/$file', 'downloads/$cat/$r/thumb.jpg', 200, 200);
?>
Go to the top of the page
+Quote Post
Cezar708
post 24.01.2008, 20:45:13
Post #5





Grupa: Zarejestrowani
Postów: 1 116
Pomógł: 119
Dołączył: 10.05.2005
Skąd: Poznań

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


no to zrób na początku funckji:

  1. <?php
  2. function makeIcons_MergeCenter($src, $dst, $dstx, $dsty){
  3.  
  4. global $cat, $r, $file;
  5.  
  6. // i dalsza część kodu
  7. ?>


pozdrawiam
Go to the top of the page
+Quote Post
Neeke
post 24.01.2008, 20:46:26
Post #6





Grupa: Zarejestrowani
Postów: 124
Pomógł: 16
Dołączył: 22.02.2007
Skąd: Warszawa

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


o boshe .......... cos takiego jak bbcody znasz? zrób to ladnie
Go to the top of the page
+Quote Post
b_chmura
post 24.01.2008, 20:52:00
Post #7





Grupa: Zarejestrowani
Postów: 813
Pomógł: 34
Dołączył: 18.03.2007
Skąd: o stamtąd

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


swoją funkcje makeIcons_MergeCenter podmień na tą:

  1. <?php
  2.  
  3. function makeIcons_MergeCenter($in, $out, $max_width, $max_height, $jakosc = 80) //mała poprawka 
  4. {
  5.  
  6. $typ = img_typ($in);
  7.  
  8. if ($typ == ".jpg") {$img_src = imagecreatefromjpeg($in);}
  9. elseif($typ == ".gif") {$img_src = imagecreatefromgif($in); }
  10. elseif($typ == ".png") {$img_src = imagecreatefrompng($in); }
  11.  
  12. $x = imagesx($img_src);
  13. $y = imagesy($img_src);
  14.  
  15. if($x > $y) 
  16. {
  17. $xr = ($x > $max_width)$max_width/$x : 1;
  18. $yr = $xr;
  19. }
  20. else 
  21. {
  22. $yr = ($y > $max_height)$max_height/$y : 1;
  23. $xr = $yr;
  24. }
  25.  
  26. $new_x = $x*$xr;
  27. $new_y = $y*$yr;
  28.  
  29. $new_img = imagecreatetruecolOR($new_x, $new_y);
  30. $background = imagecolORallocate($new_img, 255, 255, 255);
  31.  
  32. imagefill($new_img, 0, 0, $background);
  33. imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_x, $new_y, $x, $y);
  34.  
  35. $typ = img_typ($out);
  36.  
  37. if ($typ == ".jpg") {imagejpeg($new_img, $out, $jakosc);}
  38. elseif($typ == ".png") { imagepng($new_img, $out, $jakosc);}
  39. elseif($typ == ".gif") { imagegif($new_img, $out);  }
  40. }
  41. ?>


i dodaj tą:
  1. <?php
  2. function img_typ($name) 
  3. {
  4. $name = strtolower(substr($name, -4, 4));
  5.  
  6. if($name == '.jpg' OR $name == 'jpeg') 
  7. {
  8. return ".jpg";
  9. }
  10. elseif($name == '.gif') 
  11. {
  12. return ".gif";
  13. }
  14. elseif($name == '.png')
  15. {
  16. return ".png";
  17. }
  18. }
  19. ?>


Edit:
Cytat
o boshe ...

~Neekea a Ty pisać po polsku

Ten post edytował b_chmura 24.01.2008, 20:56:05
Go to the top of the page
+Quote Post
JamalBIG
post 24.01.2008, 21:23:43
Post #8





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Wyszlo cos takiego ale nadal nic... Pojawiaja sie takie ostrzezenia:

Cytat
Warning: imagesx(): supplied argument is not a valid Image resource in c:\usr\apache\httpd\html\index.php on line 45

Warning: imagesy(): supplied argument is not a valid Image resource in c:\usr\apache\httpd\html\index.php on line 46

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in c:\usr\apache\httpd\html\index.php on line 62

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in c:\usr\apache\httpd\html\index.php on line 63

Warning: imagefill(): supplied argument is not a valid Image resource in c:\usr\apache\httpd\html\index.php on line 65

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in c:\usr\apache\httpd\html\index.php on line 66

Warning: imagejpeg(): supplied argument is not a valid Image resource in c:\usr\apache\httpd\html\index.php on line 70


  1. <?php
  2. if ($cat == "c1") {
  3. $cat = "videos";
  4. } else {
  5. $cat = "torrents";
  6. }
  7. $file = $_FILES['my_file']['name'];
  8. $file = str_replace(' ', '', $file);
  9. $r = explode('.',$file);
  10. $r = $r[0];
  11. $r = str_replace(' ', '', $r);
  12.  
  13. $filename = "downloads/$cat/$file";
  14. if (file_exists($filename)) {
  15. echo "Plik $filename juz istnieje $file";
  16. } else {
  17. mkdir ("downloads/$cat/$r");
  18.  if(isset($_FILES['my_file'])) {
  19. if(is_uploaded_file($_FILES['my_file']['tmp_name'])) {
  20. move_uploaded_file($_FILES['my_file']['tmp_name'], "downloads/$cat/$r/$file");
  21. }
  22. }
  23. $pic = $_FILES['my_pic']['name'];
  24. $pic = str_replace(' ', '', $pic);
  25. $p = explode('.',$pic);
  26. $p = $r[0];
  27. $p = str_replace(' ', '', $p);
  28. if(isset($_FILES['my_pic'])) {
  29. if(is_uploaded_file($_FILES['my_pic']['tmp_name'])) {
  30. move_uploaded_file($_FILES['my_pic']['tmp_name'], "downloads/$cat/$r/$pic");
  31. }
  32. }
  33. echo "Plik downloads/$cat/$r/$file zostal dodany";
  34. }
  35.  
  36. function makeIcons_MergeCenter($in, $out, $max_width, $max_height, $jakosc = 80) //mała poprawka 
  37. {
  38.  
  39. $typ = img_typ($in);
  40.  
  41. if ($typ == ".jpg") {$img_src = imagecreatefromjpeg($in);}
  42. elseif($typ == ".gif") {$img_src = imagecreatefromgif($in); }
  43. elseif($typ == ".png") {$img_src = imagecreatefrompng($in); }
  44.  
  45. $x = imagesx($img_src);
  46. $y = imagesy($img_src);
  47.  
  48. if($x > $y) 
  49. {
  50. $xr = ($x > $max_width)$max_width/$x : 1;
  51. $yr = $xr;
  52. }
  53. else 
  54. {
  55. $yr = ($y > $max_height)$max_height/$y : 1;
  56. $xr = $yr;
  57. }
  58.  
  59. $new_x = $x*$xr;
  60. $new_y = $y*$yr;
  61.  
  62. $new_img = imagecreatetruecolOR($new_x, $new_y);
  63. $background = imagecolORallocate($new_img, 255, 255, 255);
  64.  
  65. imagefill($new_img, 0, 0, $background);
  66. imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_x, $new_y, $x, $y);
  67.  
  68. $typ = img_typ($out);
  69.  
  70. if ($typ == ".jpg") {imagejpeg($new_img, $out, $jakosc);}
  71. elseif($typ == ".png") { imagepng($new_img, $out, $jakosc);}
  72. elseif($typ == ".gif") { imagegif($new_img, $out);  }
  73. }
  74.  
  75. function img_typ($name) 
  76. {
  77. $name = strtolower(substr($name, -4, 4));
  78.  
  79. if($name == '.jpg' OR $name == 'jpeg') 
  80. {
  81. return ".jpg";
  82. }
  83. elseif($name == '.gif') 
  84. {
  85. return ".gif";
  86. }
  87. elseif($name == '.png')
  88. {
  89. return ".png";
  90. }
  91. }
  92.  
  93. makeIcons_MergeCenter('downloads/$cat/$r/$file', 'downloads/$cat/$r/thumb.jpg', 200, 200);
  94. ?>
Go to the top of the page
+Quote Post
b_chmura
post 24.01.2008, 22:01:29
Post #9





Grupa: Zarejestrowani
Postów: 813
Pomógł: 34
Dołączył: 18.03.2007
Skąd: o stamtąd

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


sprawdź dobrze co kryje sie pod ścieżką downloads/$cat/$r/$file
Go to the top of the page
+Quote Post
JamalBIG
post 24.01.2008, 22:08:25
Post #10





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Wszystko jest ok bo fotka mi sie dobrze uploaduje, katalog sie tworzy tylko ta nieszczesna miniaturka nie chce sie 'zrobic'.... Calkowicie nie wiem dlaczego....
W tej postaci dziala, w tej powyzej juz nie...

  1. <?php
  2.  
  3. function makeIcons_MergeCenter($in, $out, $max_width, $max_height, $jakosc = 80) //mała poprawka 
  4. {
  5.  
  6. $typ = img_typ($in);
  7.  
  8. if ($typ == ".jpg") {$img_src = imagecreatefromjpeg($in);}
  9. elseif($typ == ".gif") {$img_src = imagecreatefromgif($in); }
  10. elseif($typ == ".png") {$img_src = imagecreatefrompng($in); }
  11.  
  12. $x = imagesx($img_src);
  13. $y = imagesy($img_src);
  14.  
  15. if($x > $y) 
  16. {
  17. $xr = ($x > $max_width)$max_width/$x : 1;
  18. $yr = $xr;
  19. }
  20. else 
  21. {
  22. $yr = ($y > $max_height)$max_height/$y : 1;
  23. $xr = $yr;
  24. }
  25.  
  26. $new_x = $x*$xr;
  27. $new_y = $y*$yr;
  28.  
  29. $new_img = imagecreatetruecolOR($new_x, $new_y);
  30. $background = imagecolORallocate($new_img, 255, 255, 255);
  31.  
  32. imagefill($new_img, 0, 0, $background);
  33. imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_x, $new_y, $x, $y);
  34.  
  35. $typ = img_typ($out);
  36.  
  37. if ($typ == ".jpg") {imagejpeg($new_img, $out, $jakosc);}
  38. elseif($typ == ".png") { imagepng($new_img, $out, $jakosc);}
  39. elseif($typ == ".gif") { imagegif($new_img, $out);  }
  40. }
  41.  
  42. function img_typ($name) 
  43. {
  44. $name = strtolower(substr($name, -4, 4));
  45.  
  46. if($name == '.jpg' OR $name == 'jpeg') 
  47. {
  48. return ".jpg";
  49. }
  50. elseif($name == '.gif') 
  51. {
  52. return ".gif";
  53. }
  54. elseif($name == '.png')
  55. {
  56. return ".png";
  57. }
  58. }
  59.  
  60. makeIcons_MergeCenter('test.jpg', 'nazwa.jpg', 200, 200);
  61. ?>


Ten post edytował JamalBIG 24.01.2008, 22:10:13
Go to the top of the page
+Quote Post
b_chmura
post 24.01.2008, 22:18:02
Post #11





Grupa: Zarejestrowani
Postów: 813
Pomógł: 34
Dołączył: 18.03.2007
Skąd: o stamtąd

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


spróbuj tak
  1. <?php
  2. function makeIcons_MergeCenter($in, $out, $max_width, $max_height, $jakosc = 80) 
  3. {
  4.  
  5. $typ = img_typ($in);
  6. /*
  7. if ($typ == ".jpg") {$img_src = imagecreatefromjpeg($in);}
  8. elseif($typ == ".gif") {$img_src = imagecreatefromgif($in); }
  9. elseif($typ == ".png") {$img_src = imagecreatefrompng($in); }
  10. */
  11. $img_src = $in;
  12. $x = imagesx($img_src);
  13. $y = imagesy($img_src);
  14.  
  15. if($x > $y) 
  16. {
  17. $xr = ($x > $max_width)$max_width/$x : 1;
  18. $yr = $xr;
  19. }
  20. else 
  21. {
  22. $yr = ($y > $max_height)$max_height/$y : 1;
  23. $xr = $yr;
  24. }
  25.  
  26. $new_x = $x*$xr;
  27. $new_y = $y*$yr;
  28.  
  29. $new_img = imagecreatetruecolOR($new_x, $new_y);
  30. $background = imagecolORallocate($new_img, 255, 255, 255);
  31.  
  32. imagefill($new_img, 0, 0, $background);
  33. imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_x, $new_y, $x, $y);
  34.  
  35. $typ = img_typ($out);
  36.  
  37. if ($typ == ".jpg") {imagejpeg($new_img, $out, $jakosc);}
  38. elseif($typ == ".png") { imagepng($new_img, $out, $jakosc);}
  39. elseif($typ == ".gif") { imagegif($new_img, $out);  }
  40. }
  41. ?>


ale nie obiecuje, nie mam na razie jak testować.
Go to the top of the page
+Quote Post
JamalBIG
post 24.01.2008, 23:20:42
Post #12





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


w wierszu 90

  1. <?php
  2. makeIcons_MergeCenter('downloads/$cat/$r/$file', 'downloads/$cat/$r/thumb.jpg', 200, 200);
  3. ?>


trzeba tylko zmienic ' na " i wszystko chodzi gladko... taki pierdol a potrafi zepsuc wszystko, ale mimo to dzieki wszystkim za pomoc!

  1. <?php
  2. makeIcons_MergeCenter("downloads/$cat/$r/$file", "downloads/$cat/$r/thumb.jpg", 200, 200);
  3. ?>
Go to the top of the page
+Quote Post
b_chmura
post 24.01.2008, 23:26:56
Post #13





Grupa: Zarejestrowani
Postów: 813
Pomógł: 34
Dołączył: 18.03.2007
Skąd: o stamtąd

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


gapa ze mnie

ewentulanie
  1. <?php
  2. makeIcons_MergeCenter('downloads/'.$cat.'/'.$r.'/'.$file, 'downloads/'.$cat.'/'.$r.'/thumb.jpg', 200, 200);
  3. ?>
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: 3.07.2025 - 01:49