Avatar billede taitech2006 Nybegynder
11. december 2004 - 16:36 Der er 10 kommentarer

Hent filnavn ind i et feldt i et recordset

Jeg har lavet en upload funktion på min hjemmeside med Dreamweaver extensionen PureASP Upload, nu skal jeg have sådan at den kan tage kun selve filnavnet altså vi nu jeg henter en fil ind fra adressen

C:\Mine Billeder\Billeder2\hanserik.jpg

når så den har uploadet billeder til mappen skal den gå ind og tage navnet på det sidste uploadet billede altså istedet for at den indskriver adressen C:\Mine Billeder\Billeder2\hanserik.jpg så skal den kun tager hanserik.jpg og ligge ind i tabellen...

Med Venlig Hilsen

TaiTech2006
Avatar billede ellebaek Nybegynder
12. december 2004 - 13:31 #1
hmm...

du kan hente filnavnet ud ved at bruge:

<%
str = "C:\Mine Billeder\Billeder2\hanserik.jpg"
filnavn = right(str,instrrev(str,"\"))
%>

så skal du bare ligge variablen filnavn ind i databasen...
Avatar billede taitech2006 Nybegynder
13. december 2004 - 16:49 #2
okay men hvor skal jeg placerer det du lige har skrevet?
Avatar billede ellebaek Nybegynder
14. december 2004 - 17:24 #3
det skal bare placeres inden du vil sætte det ind i databasen..

og så indsætter du variablen filnavn i databasen..
Avatar billede taitech2006 Nybegynder
24. februar 2005 - 12:41 #4
jammen str ="C:\blabalbalba" er jo ikke altid den samme adresse hvergang...
Avatar billede taitech2006 Nybegynder
24. februar 2005 - 12:42 #5
og variablen er det en session eller hvad?
Avatar billede ellebaek Nybegynder
03. marts 2005 - 22:14 #6
selvom det ikke er det samme hver gang, så skal der altså bare skrives som jeg skriver, det virker helt sikker..!
Avatar billede ellebaek Nybegynder
03. marts 2005 - 22:14 #7
str skal være dit filnavn..!
Avatar billede taitech2006 Nybegynder
06. marts 2005 - 21:21 #8
skal jeg så bare indsætte det her i et hiddenfield

<%= Request("filnavn") %>
Avatar billede taitech2006 Nybegynder
06. marts 2005 - 21:32 #9
her er hvordan mine sider ser ud:

**** Siden Hvor Man Vælger Billedet I En Filform ****

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../ScriptLibrary/incPureUpload.asp" -->
<%
'*** Pure ASP File Upload -----------------------------------------------------
' Copyright (c) 2001-2002 George Petrov, www.UDzone.com
' Process the upload
' Version: 2.0.9
'------------------------------------------------------------------------------
'*** File Upload to: """../files/gfx/profiler""", Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: form1, Redirect: "profilbillede2.asp", "file", "250", "uniq", "true", "0", "0" , "320", "240", "", "", "650", "fileCopyProgress.htm", "300", "100"

Dim GP_redirectPage, RequestBin, UploadQueryString, GP_uploadAction, UploadRequest
PureUploadSetup

If (CStr(Request.QueryString("GP_upload")) <> "") Then
  on error resume next
  Dim reqPureUploadVersion, foundPureUploadVersion
  reqPureUploadVersion = 2.09
  foundPureUploadVersion = getPureUploadVersion()
  if err or reqPureUploadVersion > foundPureUploadVersion then
    Response.Write "<b>You don't have latest version of ScriptLibrary/incPureUpload.asp uploaded on the server.</b><br>"
    Response.Write "This library is required for the current page. It is fully backwards compatible so old pages will work as well.<br>"
    Response.End   
  end if
  on error goto 0
  GP_redirectPage = "profilbillede2.asp"
  Server.ScriptTimeout = 650
 
  RequestBin = Request.BinaryRead(Request.TotalBytes)
  Set UploadRequest = CreateObject("Scripting.Dictionary") 
  BuildUploadRequest RequestBin, """../files/gfx/profiler""", "file", "250", "uniq"
 
  If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("MM_insert")) <> "" or CStr(UploadFormRequest("MM_update")) <> "")) Then
    If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
      GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
    End If
    Response.Redirect(GP_redirectPage) 
  end if 
else
  if UploadQueryString <> "" then
    UploadQueryString = UploadQueryString & "&GP_upload=true"
  else 
    UploadQueryString = "GP_upload=true"
  end if 
end if
' End Pure Upload
'------------------------------------------------------------------------------
%>
<html>
<head>
<script language="JavaScript">
<!--

function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
  document.MM_returnValue = true;
  for (var i = 0; i<form.elements.length; i++) {
    field = form.elements[i];
    if (field.type.toUpperCase() != 'FILE') continue;
    checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
} }

function checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
  document.MM_returnValue = true;
  if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|").replace(/\s/gi,"") + ")$","i");
    if (field.value == '') {
      if (requireUpload) {alert('File is required!');document.MM_returnValue = false;field.focus();return;}
    } else {
      if(extensions != '' && !re.test(field.value)) {
        alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
        document.MM_returnValue = false;field.focus();return;
      }
    document.PU_uploadForm = field.form;
    re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
    if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
      checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    } }
}

function showImageDimensions(fieldImg) { //v2.09
  var isNS6 = (!document.all && document.getElementById ? true : false);
  var img = (fieldImg && !isNS6 ? fieldImg : this);
  if (img.width > 0 && img.height > 0) {
  if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
    alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
  if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
    alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
  if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
    alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
  if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
  if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
  document.MM_returnValue = true;
} }

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.09
  if (!document.layers) {
    var isNS6 = (!document.all && document.getElementById ? true : false);
    document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
    if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
          with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
        gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
    } else showImageDimensions(field.gp_img);}
}

function showProgressWindow(progressFile,popWidth,popHeight) { //v2.09
  var showProgress = false, form, field;
  for (var f = 0; f<document.forms.length; f++) {
    form = document.forms[f];
    for (var i = 0; i<form.elements.length; i++) {
      field = form.elements[i];
      if (field.type.toUpperCase() != 'FILE') continue;
      if (field.value != '') {showProgress = true;break;}
  } }
  if (showProgress && document.MM_returnValue) {
    var w = 480, h = 340;
    if (document.all || document.layers || document.getElementById) {
      w = screen.availWidth; h = screen.availHeight;}
    var leftPos = (w-popWidth)/2, topPos = (h-popHeight)/2;
    document.progressWindow = window.open(progressFile,'ProgressWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + popWidth + ',height='+popHeight);
    document.progressWindow.moveTo(leftPos, topPos);document.progressWindow.focus();
        window.onunload = function () {document.progressWindow.close();};
} }
//-->
</script>
<title>Danling.dk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../files/css/css.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ramme">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabel_top">
        <tr>
          <td>Profilbillede
            <%
str = "C:\Mine Billeder\Billeder2\hanserik.jpg"
filnavn = right(str,instrrev(str,"\"))
%>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <form name="form1" method="post" action="<%=GP_uploadAction%>" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,250,0,0,320,240,'','');showProgressWindow('fileCopyProgress.htm',300,100);return document.MM_returnValue">
              <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tekst_normal">
                <tr>
                  <td>&#149; Billedet m&aring; ikke fylde mere end 250 kb</td>
                </tr>
                <tr>
                  <td>&#149; Billedet m&aring; ikke v&aelig;re st&oslash;rrer
                    end 320x240</td>
                </tr>
                <tr>
                  <td>&#149; Billedet m&aring; ikke v&aelig;re af pornografisk
                    / erotisk matriale</td>
                </tr>
                <tr>
                  <td>
                    <input type="file" name="file" class="box2x" onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,250,0,0,320,240,'','')">
                    <input type="submit" name="Submit" value="Upload" class="knap2">
                  </td>
                </tr>
              </table>
            </form>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabel_bottom">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>

**** Siden Hvor Filnavn bliver lagt ind som billede i bruger tabellen ****

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/danling.asp" -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  MM_editConnection = MM_danling_STRING
  MM_editTable = "brugere"
  MM_editColumn = "brugerid"
  MM_recordId = "" + Request("MM_recordId") + ""
  MM_editRedirectUrl = "profilbillede3.asp"
  MM_fieldsStr  = "hiddenField|value"
  MM_columnsStr = "foto|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  ' create the sql update statement
  MM_editQuery = "update " & MM_editTable & " set "
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_editQuery = MM_editQuery & ","
    End If
    MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
  Next
  MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

  If (Not MM_abortEdit) Then
    ' execute the update
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
if (Session("MM_Username") <> "") then Recordset1__MMColParam = Session("MM_Username")
%>
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_danling_STRING
Recordset1.Source = "SELECT * FROM brugere WHERE mail = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
<html>
<head>
<title>Danling.dk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../files/css/css.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ramme">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabel_top">
        <tr>
          <td>Profilbillede</td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <form name="form2" method="POST" action="<%=MM_editAction%>">
              <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tekst_normal_3xgreen">
                <tr>
                  <td>Billedet Er Uploadet !
                    <input type="hidden" name="hiddenField" value="<%= Request("filnavn") %>">
                  </td>
                </tr>
                <tr>
                  <td>
                    <input type="submit" name="Submit2" value="Tjek Billede" class="knap2">
                  </td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="true">
              <input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("brugerid").Value %>">
            </form>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabel_bottom">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<%
Recordset1.Close()
%>

**** Siden hvor brugere accepterer billedet ****

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/danling.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
if (Session("MM_Username") <> "") then Recordset1__MMColParam = Session("MM_Username")
%>
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_danling_STRING
Recordset1.Source = "SELECT * FROM brugere WHERE mail = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
<html>
<head>
<title>Danling.dk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../files/css/css.css" type="text/css">
<script language="JavaScript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ramme">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabel_top">
        <tr>
          <td>Profilbillede</td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tekst_center_2x">
        <tr>
          <td>Vil du bruge dette billedet ?</td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tekst_center_2x">
        <tr>
          <td><img src="files/gfx/profiler/<%=(Recordset1.Fields.Item("foto").Value)%>" class="profilfoto"></td>
        </tr>
        <tr>
          <td>
            <input type="button" name="Button" value="Ja" class="knap2" onClick="MM_goToURL('self','profilbillede4.asp');return document.MM_returnValue">
            <input type="button" name="Button2" value="Nej" class="knap2" onClick="MM_goToURL('self','profilbillede.asp');return document.MM_returnValue">
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabel_bottom">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<%
Recordset1.Close()
%>
Avatar billede taitech2006 Nybegynder
06. marts 2005 - 21:33 #10
Hvorfor er det så lige at jeg ikke kan få det til at fungere som du siger
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester