Hi Friends in my project i have to build file input tag to get pdf file from user. this pdf file should be store on my web server disc and path of the file should be store on database.
Hey Guys Please Please Help Me.
can any body give me the code or example or link to that page please guys help me out.
:S:S

Dani AI

Generated

asked how to accept a PDF via a file input, save it on disk, and store the path in a database. started a reply but didn’t include working code, and pointed to a free upload utility. The most reliable patterns are the same now as back then: (1) HTML form with multipart POST, (2) a server-side upload parser or component to get the file bytes, (3) strict validation (type, extension, size, PDF header), (4) save with a safe, unique filename, and (5) insert the relative path and metadata into the DB.

Use a simple HTML form like this:

<form method="post" enctype="multipart/form-data" action="upload.asp">
  <input type="file" name="pdfFile" accept="application/pdf" />
  <input type="submit" value="Upload PDF" />
</form>

A practical Classic ASP server-side pattern (common with components such as Persits.Upload) — validate, generate a GUID-based filename, save the file, then persist the path:

<%
Set Upload = Server.CreateObject("Persits.Upload.1")
' iterate uploaded files
For Each f in Upload.Files
  If f.FileName <> "" Then
    ' quick validation (check extension + MIME)
    pos = InStrRev(f.FileName, ".")
    If pos = 0 Or LCase(Mid(f.FileName,pos+1)) <> "pdf" Then
      ' skip / log invalid file
    Else
      ' create GUID filename to avoid collisions
      Set g = Server.CreateObject("Scriptlet.TypeLib")
      ext = ".pdf"
      uniqueName = Mid(g.Guid,2,36) & ext
      Set g = Nothing

      f.SaveAs Server.MapPath("/uploads/" & uniqueName)
      savedPath = "/uploads/" & uniqueName

      ' save metadata (original name, saved path, date) using ADODB.Recordset or parameterized command
      Set rs = Server.CreateObject("ADODB.Recordset")
      rs.Open "SELECT FileName,FilePath,UploadDate FROM Files WHERE 1=0", conn, 2, 3
      rs.AddNew
      rs("FileName") = f.FileName
      rs("FilePath") = savedPath
      rs("UploadDate") = Now()
      rs.Update
      rs.Close
    End If
  End If
Next
%>

Notes and troubleshooting: always validate file content (check the first bytes for "%PDF"), limit upload size, sanitize or generate filenames, set write permissions for the application pool identity (not Everyone), and consider storing files outside the webroot and serving them through a controlled handler. Storing the relative path plus original name, MIME type and upload timestamp in the DB makes later management and cleanup easier.

Recommended Answers

All 5 Replies

Hi Friends in my project i have to build file input tag to get pdf file from user. this pdf file should be store on my web server disc and path of the file should be store on database.
Hey Guys Please Please Help Me.
can any body give me the code or example or link to that page please guys help me out.
:S:S

Yes sure,

you can do

Yes sure,

you can do

Dude I want proper solution.

I'm interested in this topic, anyone knows hot to do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.