Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]formularz do uploadu fotek
pomier
post
Post #1





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 15.11.2010

Ostrzeżenie: (10%)
X----


Witam wszystkich, mam taki problem. Mam gotową baz mysql wszystko działa, wiem jak zrobić formularze do dodawania rekordów, aktualizacji i kasowania ale nie mam pojęcia jak się zabrać za formularz który będzie dodawał obrazek w wyznaczone miejsce, robił miniaturkę i zapisywał ścieszkę do obrazka wraz z tytułem w bazie mysql.

Może mnie ktoś naprowadzi, podsunie jakiś pomysł.

Dzięki
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
pomier
post
Post #2





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 15.11.2010

Ostrzeżenie: (10%)
X----


wszystko sobie sprawdzam na serwerku i w phpmyadmin to widzę co się dzieje

kod dodawania:
  1.  
  2. <form action="test.php" method="POST" ENCTYPE="multipart/form-data">
  3. <form name="form" action="<?php echo $editFormAction; ?>" method="POST" ENCTYPE="multipart/form-data">
  4. <input type="file" name="plik"/><br/>
  5. <input type="submit" value="Wyślij plik"/>
  6.  
  7. <input type="checkbox" name="aktywne" id="aktywne">
  8. aktywne</label>
  9. <label>czas
  10. <input type="text" name="czas" id="czas">
  11. </label>
  12. <input type="hidden" name="MM_insert" value="form">
  13. </form>
  14.  
  15.  


kod wykonywania
  1. <?php
  2. $max_rozmiar = 530*530;
  3. if (is_uploaded_file($_FILES['plik']['tmp_name'])) {
  4. if ($_FILES['plik']['size'] > $max_rozmiar) {
  5. echo 'Błąd! Plik jest za duży!';
  6. } else {
  7. echo 'Plik zostałwysłany. Początkowa nazwa: '.$_FILES['plik']['name'];
  8. echo '<br/>';
  9. if (isset($_FILES['plik']['type'])) {
  10. echo 'Typ: '.$_FILES['plik']['type'].'<br/>';
  11. }
  12. move_uploaded_file($_FILES['plik']['tmp_name'],
  13. $_SERVER['DOCUMENT_ROOT'].'/www.artdd.eu.xml.mysql/backgrounds/'.$_FILES['plik']['name']);
  14. }
  15. } else {
  16. echo 'Błąd przy przesyłaniu danych!';
  17. }
  18.  
  19. require_once('../Connections/mysqlartddxml.php');
  20.  
  21. if (!function_exists("GetSQLValueString")) {
  22. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  23. {
  24. if (PHP_VERSION < 6) {
  25. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  26. }
  27.  
  28. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  29.  
  30. switch ($theType) {
  31. case "text":
  32. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  33. break;
  34. case "long":
  35. case "int":
  36. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  37. break;
  38. case "double":
  39. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  40. break;
  41. case "date":
  42. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  43. break;
  44. case "defined":
  45. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  46. break;
  47. }
  48. return $theValue;
  49. }
  50. }
  51.  
  52. $editFormAction = $_SERVER['PHP_SELF'];
  53. if (isset($_SERVER['QUERY_STRING'])) {
  54. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  55. }
  56.  
  57. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  58. $insertSQL = sprintf("INSERT INTO tlo (grafika_tlo, czas_wyswietlania, Aktywne) VALUES (%s, %s, %s)",
  59.  
  60. GetSQLValueString($_FILES['plik']['name'], "text"),
  61. GetSQLValueString($_POST['czas'], "text"),
  62. GetSQLValueString(isset($_POST['aktywne']) ? "true" : "", "defined","1","0"));
  63.  
  64. mysql_select_db($database_mysqlartddxml, $mysqlartddxml);
  65. $Result1 = mysql_query($insertSQL, $mysqlartddxml) or die(mysql_error());
  66. }
  67. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 07:52