Fileupload mit Datenbankeintrag

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Fileupload mit Datenbankeintrag

    hallo,
    ich habe ein Problem mit dem eintragen von Dateinamen in eine Datenbank.
    ich möchte 2 Bilder per FTP Script uploaden und die Dateinamen in eine Datenbank schreiben. hierzu verwende ich die Variable $_files[]. leider funktioniert der Eintrag nicht. kann mir da jemand einen Tipp geben?
    hier der Code:

    <?php require_once('Connections/test.php'); ?>
    <?php

    $currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    ###### Anfang Datenbankeintrag ###############

    $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
    }

    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO image (id, url ,link, bildpopup, kunde, text) VALUES (%s, %s , %s, %s, %s, %s)",
    GetSQLValueString($HTTP_POST_VARS['id'], "int"),
    GetSQLValueString($_FILES['fileupload']['name'][$i],"text"),
    GetSQLValueString($HTTP_POST_VARS['link'], "text"),
    GetSQLValueString($_FILES['fileupload']['name'][$i],"int"),
    GetSQLValueString($HTTP_POST_VARS['kunde'], "text"),
    GetSQLValueString($HTTP_POST_VARS['text'], "text")
    );


    ###### Ende Datenbankeintrag ###############

    mysql_select_db($database_test, $test);
    $Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
    }

    mysql_select_db($database_test, $test);
    $query_Recordset1 = "SELECT * FROM image";
    $Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);

    $queryString_Recordset1 = "";
    if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
    $newParams = array();
    foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false &&
    stristr($param, "totalRows_Recordset1") == false) {
    array_push($newParams, $param);
    }
    }
    if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . implode("&", $newParams);
    }
    }
    $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
    ?>

    <?php

    ###### Anfang Fileupload ###############

    include ("upload_config.php");
    if ($_REQUEST['submitted'] == "true")
    {
    // start loop
    for ($i = 0; $i < $nof; $i++)
    {
    $userfile_name = $_FILES['fileupload']['name'][$i];
    $userfile_tmp = $_FILES['fileupload']['tmp_name'][$i];
    $userfile_size = $_FILES['fileupload']['size'][$i];
    $userfile_type = $_FILES['fileupload']['type'][$i];
    //checks if file exists
    if ($userfile_name == "") {
    echo "No file selected for upload<br>";
    }
    if ($userfile_name[$i] != "") {

    if ($userfile_size > $maxfile) {
    echo "This file is too big for uploading. It is $userfile_size bytes. Please click <a href=\"javascript:history.back(1)\">here</a> to go back and upload a smaller file.";
    exit;
    }
    // Display info
    $h = $i + 1;
    echo "<u>$h</u><br>\n";
    echo "Path: $userfile_tmp<br>\n";
    echo "Name: $userfile_name<br>\n";
    echo "Size: $userfile_size bytes<br>\n";
    echo "Type: $userfile_type<br><br>\n\n";
    echo "Click <a href=\"../$filedir/$userfile_name\">here</a> to view it<br><br>";
    // upload file
    $location = "$filedir/$userfile_name";
    move_uploaded_file($userfile_tmp, $location);

    if ($fileupload_type[$i] == "image/gif" || $fileupload_type[$i] == "image/jpeg")
    {
    echo "<img src=\"../$filedir/$userfile_name\"><br><br>\n\n";
    }

    // end of file upload
    }
    // end loop
    }

    }

    ###### Ende Fileupload ###############
    ?>




    <html>
    <head>
    <title>db images</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <link href="_notes/investeck.css" rel="stylesheet" type="text/css">
    </head>

    <body bgcolor="F1C35E">
    <span class="investeck">Datens&auml;tze <?php echo $totalRows_Recordset1 ?> </span>
    <form action="<?php echo $editFormAction; ?><? echo $_SERVER["PHP_SELF"] ?>" method="post" enctype="multipart/form-data" name="form1">
    <input type="hidden" name="submitted" value="true">

    <table width="383" align="left">
    <tr valign="baseline">
    <td width="83" align="right" nowrap class="investeck">Ordner:</td>
    <td width="162" class="investeck"> <select name="link" size=1 class="investeck">
    <option selected>Bitte w&auml;hlen!</option>
    <option value="grafik">Grafik</option>
    <option value="web">Web</option>
    <option value="print">Print</option>
    </select></td>
    <td colspan="2" rowspan="2" class="investeck">vorhandene<br>
    Bilder</span><br> </td>
    </tr>
    <tr valign="baseline">
    <td align="right" valign="baseline" nowrap class="investeck">Bild:</td>
    <td rowspan="2" class="investeck">
    <?php
    for ($j = 1; $j <= $nof; $j++)
    {
    echo "<input type=\"file\" name=\"fileupload[]\"><br>";
    }
    ?>
    </td>
    </tr>
    <tr valign="baseline">
    <td align="right" nowrap class="investeck">Bild Popup:</td>
    <td width="35" class="investeck">
    <?php $result = mysql_query("SELECT url FROM image");
    while($row = mysql_fetch_array($result)) {
    echo $row ['url']."<br>"; }
    ?>
    </td>
    <td width="83" class="investeck">
    <?php $result = mysql_query("SELECT link FROM image");
    while($row = mysql_fetch_array($result)) {
    echo $row ['link']."<br>"; }
    ?>
    </td>
    </tr>
    <tr valign="baseline">
    <td align="right" nowrap class="investeck">Kunde</td>
    <td class="investeck"><input name="kunde" type="text" class="investeck" id="kunde" ></td>
    <td class="investeck">&nbsp;</td>
    <td class="investeck">&nbsp;</td>
    </tr>
    <tr valign="baseline">
    <td align="right" valign="top" nowrap class="investeck">Text</td>
    <td class="investeck"><textarea name="text" class="investeck" id="text"></textarea></td>
    <td class="investeck">&nbsp;</td>
    <td class="investeck">&nbsp;</td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right">&nbsp;</td>
    <td class="investeck"><input name="submit" type="submit" class="investeck" value="Bild einf&uuml;gen"></td>
    <td class="investeck">&nbsp;</td>
    <td class="investeck">&nbsp;</td>
    </tr>
    </table>
    <input type="hidden" name="MM_insert" value="form1">
    </form>



    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>
    Zuletzt geändert von bepage; 16.12.2002, 21:36.

  • #2
    hast du dich auch mal der suche bedient?
    das gabs schon sehr oft, wenn ich mich nicht irre.
    suche auch mal im php-forum danach.
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar


    • #3
      Lösung gefunden !!!!

      hi,
      nach etwas gebastel hab ich die Lösung selbst gefunden.
      für alle die es interessiert, der Datenbank String müss so aussehen:

      GetSQLValueString($HTTP_POST_FILES["img"]['name'][0], "text"),


      und für das zweite Bild


      GetSQLValueString($HTTP_POST_FILES["img"]['name'][1], "text"),


      dann werden die beiden Bildnamen in die DB eingetragen

      Kommentar

      Lädt...
      X