Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php / mysql ] dodawanie plikow przez skrypt na strone
Forum PHP.pl > Forum > Przedszkole
andy84
czesc
Chcialem zrobic proste dodawanie na strone grafiki i jej miniatury znalazlem skrypcik ktory dodaje nazwe i sciezke do bazy, chcialem go powielic jednak cos czuje ze nie tedy droga mozna jakos sprawniej zrobic takie dodawanie questionmark.gif - drobna uwaga staram sie aby pliki ladowane w tym samym momecie uploadowaly sie do dwochy roznych miejsc
  1. <?
  2.  
  3. if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) {
  4. // not logged in, move to login page
  5. header('Location: ../login_go.php');
  6. }
  7. ?>
  8. <form method="post" enctype="multipart/form-data">
  9. <table width="95%" border="0">
  10. <tr>
  11. <td width="45%"><a href="control.php?location=listportfolio" class="link">List all entrees</a></td>
  12. <td width="55%">&nbsp;</td>
  13. </tr>
  14. <tr>
  15. <td><div id="panel" align="right">image:</div></td>
  16. <td><input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  17. <input name="userfile" type="file" id="userfile" /></td>
  18. </tr>
  19. <tr>
  20. <td><div id="panel" align="right">thumb image:</div></td>
  21. <td><input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  22. <input name="thumbuserfile" type="file" id="thumbuserfile" /></td>
  23. </tr>
  24. <tr>
  25. <td><div id="panel" align="right">URL:</div></td>
  26. <td><input name="port_url" type="text" value="" size="50" maxlength="50" class="box" /> </td>
  27. </tr>
  28. <tr>
  29. <td valign="top" align="right"><div id="panel">short description:</div> </td>
  30. <td><textarea name="description" cols="45" rows="12" class="box" ></textarea></td>
  31. </tr>
  32. <tr>
  33. <td>&nbsp;</td>
  34. <td><div id="panel"><input type="checkbox" name="tablica[0]" value="1" > 
  35. - Mark it to make this portfolio visable on website</div><br />
  36.  
  37. </td>
  38. </tr>
  39. <tr>
  40. <td>&nbsp;</td>
  41. <td><input name="upload" type="submit" class="box" id="upload" value=" Submit "></td>
  42. </tr>
  43. </table>
  44.  
  45.  
  46. <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
  47. <tr> 
  48. <td width="246">
  49.  
  50. </td>
  51. <td width="80"></td>
  52. </tr>
  53. </table>
  54. </form>
  55.  
  56.  
  57. <?php
  58. $uploadDir = 'c:/appserv/www/websign/graphic/portfolio/';
  59. $uploadthumbsDir = 'c:/appserv/www/websign/graphic/portfolio/thumbs/';
  60. if(isset($_POST['upload']))
  61. {
  62. $fileName = $_FILES['userfile']['name'];
  63. $tmpName = $_FILES['userfile']['tmp_name'];
  64. $fileSize = $_FILES['userfile']['size'];
  65. $fileType = $_FILES['userfile']['type'];
  66.  
  67. $thumbfileName = $_FILES['thumbuserfile']['thumb_name'];
  68. $thumbtmpName = $_FILES['thumbuserfile']['thumb_tmp_name'];
  69. $thumbfileSize = $_FILES['thumbuserfile']['thumb_size'];
  70. $thumbfileType = $_FILES['thumbuserfile']['thumb_type'];
  71.  
  72. $description=$_POST['description'];
  73. $port_url=$_POST['port_url'];
  74. $date=date("Ymd");
  75. $filePath = $uploadDir . $fileName;
  76. $thumbfilePath = $uploadthumbDir . $thumbfileName;
  77.  
  78. $result = move_uploaded_file($tmpName, $filePath);
  79. $thumbresult = move_uploaded_file($thumbtmpName, $thumbfilePath);
  80. if (!$result ) {
  81. echo "Error uploading file";
  82. }
  83.  
  84. include("../config.inc.php"); 
  85. mysql_connect($host,$user,$password);
  86. @mysql_select_db($database) or die ("Unable to select database");
  87.  
  88. {
  89. $fileName = addslashes($fileName);
  90. $filePath = addslashes($filePath);
  91. $thumbfileName = addslashes($thumbfileName);
  92. $thumbfilePath = addslashes($thumbfilePath);
  93. } 
  94.  
  95. $array = $_POST['tablica'];
  96. $string = NULL;
  97. for( $i = 0; 
  98. $i <= 0; $i++ ) 
  99. {
  100. if( ! isset ( $array[ $i ] ) )
  101. $string .= 0;
  102. else
  103. $string .= $array[ $i ];
  104. } 
  105.  
  106. $query = "INSERT INTO portfolio (name, size, type, path, description, port_url, string, date, altname, thumb
    _name, thumb_type, thumb_size, thumb_path )"
    .
  107. "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$description', '$port_url', '$string', '$date', 'commingsoon.gif', '$thumbfileName', '$thumbfileType','$thumbfileSize', '$thumbfilePath')";
  108.  
  109. mysql_query($query) or die('Error, query failed : ' . mysql_error()); 
  110.  
  111.  
  112.  
  113. echo "<br>File has been uploaded<br>";
  114.  
  115. }
  116. ?>

dzieki za wskazowki pozdrowka
MacPain
Wrzuæ grafike do bazy.
andy84
potrzebuje grafike w katalogu nie w bazie ;] w bazie chce tylko sciezki i nazwe pliku trzymac nic wiecej,
nexis
Cytat
Wrzuæ grafike do bazy.


Bardzo kiepska rada - takich rzeczy siê nie robi!
MacPain
Cytat(nexis @ 19.06.2007, 22:17:41 ) *
Bardzo kiepska rada - takich rzeczy siê nie robi!

Dlaczego nie, w ma³ych projektach mo¿e byæ. Ostatnio robi³em i jest OK.
andy84
Cytat(MacPain @ 19.06.2007, 22:28:55 ) *
Dlaczego nie, w ma³ych projektach mo¿e byæ. Ostatnio robi³em i jest OK.

1. kto powiedzial ze to bedzie maly projekt ;]
2. do bazy wrzucam czasami grafike jezeli nie ma na samej bazie duzego obciazenia

jezeli strona ma ustawiona grafike i ja za kazdym razem skrypt musi wyciagac zaladowac itd pomysl jak baza jest sama w sobie tym obciazona + server - ja tam wole zyc w zgodzie z elektronami smile.gif i jezeli to nie sa kodowane dane ani jakies dokumenty ktore wolal bym trzymac bezpiecznie ( wtedy bym to do bazy wrzucil ) to trzymam to na serverze zapisane - szybszy latwiejszy dostep , ale my tu gadu gadu a nadal nie ma sugestji co moze byc nie tak z tym skryptem smile.gif pozdro smile.gif
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.