Skip to main content
GameDev.net gamedev.net
🔒 Locked

Web help needed (probably simple)

Started by AndreTheGiant May 8, 2004 at 1:03 PM 2 replies 400+ views
Original Post
AndreTheGiant
AndreTheGiant
Im not sure if this belongs in "general programming" or "the lounge", because we dont have a forum specifically for Web stuff. Anyway, here is what I want to do. I dont need anything fancy, but I have a few requirements that I cant do without: I have that deal from 1&1 where I get 500 megs of web space. I want to make it so People can upload anything to that space, provided I have given them the password. I want to be able to display the files that are currently on the webspace, and I want to display how much space, out of 500 megs, is taken up. Ive got experience with web stuff, specifically HTML, ASP, Javascript, Perl... I want to know if anyone can help me out real quick by giving me some key advice. **** Specifically, if someone could recommend a language, or set of languages, and maybe point me to a good tutorial, or tell me something important that they have learned while making something similar. **** Also, something important is that you can upload multiple files at a time, so that if the person wants to upload say 100 pictures, it doesnt take all day to do it one at a time. Maybe even upload entire folders(including subfolders) would be nice.
Coward
Coward
Well, I'm positive that it can be done in ASP, but I would rather recomend PHP for it... (Because I don't know ASP )

As in how to do it, the interface you can write yourself hopefully (with next to no HTML experience)

Then I would recomend starting with actualy having a couple of files manualy uploaded to the directory and start with the directory structure at the left.. (giving you chose PHP, the needed documentation can be found here)

Then go to the acutaly uploading part...
Create a file, upload.php that the form in your main page will refer to (the file inputs in your form will be named file0-x):

<?PHP
if($HTTP_POST_VARS[password] == "hardcodedpassword") {
$FILES = $HTTP_POST_FILES;
$i = 0;
while($FILES["file$i"]) {
copy($FILES["file$i"][tmp_name], $FILES["file$i"][name]);
$i++;
}
}
?>
<html><script>document.location="mainpage";</script></html>


The trick with more file uploads at a time is to have a div tab inside your form that will dynamicly add a new upload field whenever you add a file to the former..

[edited by - Coward on May 8, 2004 5:20:38 PM]
Don't Temp Fate..
aftermath
aftermath
Do some looking at HotScripts/PHP nad I can gaurantee you that you will find the script for a small file manager like you want. I remember seeing a lot of those there.
Rate me up.
Jason Zelos
Jason Zelos
ASP Script for uploading files.

I generally keep a session var active to tell me if anyone is logged in. May be better off using a reseller account with multiple FTP's if you get a lot of people using it.

(The bit at the bottom lists the files in the dir under the file form.)

Sorry for the scrappy appearence, I've just copied it from some code sitting on my drive.

Jay


<% If Not(Session("Username")<>"") Then Response.Redirect("Default.asp")%>
<!-- #include file="
Header.asp" -->
<%

Dim SavePath, ForWriting, adLongVarChar, lngNumberUploaded
Dim noBytes, binData, RST, LenBinary, strDataWhole, strBoundry
Dim lngBoundryPos, lngCurrentBegin, lngCurrentEnd, CountLoop, strData
Dim lngBeginFileName, lngEndFileName, strFileName, tmpLng, PrevPos
Dim FileName, lngCT, lngBeginPos, lngEndPos, lngDataLenth
Dim strFileData, fso, f, fo, Boundry

SavePath = Server.Mappath("
Images")

Server.ScriptTimeout=90
ForWriting = 2

adLongVarChar = 201
lngNumberUploaded = 0

'Get binary data from form
noBytes = Request.TotalBytes
binData = Request.BinaryRead (noBytes)

'convert the binary data to a string
Set RST = CreateObject("
ADODB.Recordset")
LenBinary = LenB(binData)

Set fso = CreateObject("
Scripting.FileSystemObject")
'Response.Write("
Byte Length:" & LenBinary)

If LenBinary > 0 Then
RST.Fields.Append "
myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("
myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("
myBinary")

' Response.Write(strDataWhole)

'get the boundry indicator
strBoundry = Request.ServerVariables ("
HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"
boundary=") + 8
strBoundry = "
--" & right(strBoundry,len(strBoundry)-lngBoundryPos)


'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1

countloop = 0

Do While lngCurrentEnd > 0

'Get the data between current boundry and remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, (lngCurrentEnd - lngCurrentBegin) + 1)

'Get the full path of the current file.
lngBeginFileName = instr(1,strdata,"
filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34))

If lngBeginFileName <> lngEndFileName and lngBeginFileName - 10 > 0 Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)

'Lose the path information and keep just the file name.

tmpLng = instr(1,strFilename,"
\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"
\")
Loop

FileName = right(strFilename,len(strFileName) - PrevPos)

'check for extension as we do not want .exe's on the server
Dim N
N=InStrRev(FileName,"
.")
If (N=0) Then
FileName=FileName & "
.jpg" 'no extension
Else
FileName = Mid(FileName,1,N) & "
jpg" 'replace extension with .doc
End If



'Get the begining position of the file data sent.
'if the file type is registered with the browser then there will be a
'Content-Type

lngCT = instr(1,strData,"
Content-Type:")

if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
Else
lngBeginPos = lngEndFileName
End if

'Get the ending position of the file data sent.

lngEndPos = len(strData)

'Calculate the file size.
lngDataLenth = (lngEndPos - lngBeginPos) -1

'Get the file data
strFileData = mid(strData,lngBeginPos,lngDataLenth)

'Create the file.
Set f = fso.OpenTextFile(SavePath & "
\" & FileName, ForWriting, True)
f.Write strFileData
Set f = nothing
End if

'Get then next boundry postitions if any.
lngCurrentBegin = lngCurrentEnd
lngCurrentEnd = instr(lngCurrentBegin + 9 ,strDataWhole,strBoundry) - 1

'Prevents infinate loop.
countloop = countloop + 1
if countloop = 100 Then
Response.Redirect("
UploadFailed.asp")
End if
loop
End If
%>
<h3>File Upload</h3>
<form action="
Upload.asp" enctype="multipart/form-data" method="post">
Image File(s): <input name="
file" type="file" size="80" /><br />
<input name="
SubmitUpload" type="submit" value="Upload" />
</form>
<textarea rows="
15" cols="80">
<%
Set fo = fso.GetFolder(SavePath)
For Each f In fo.files
'Response.Write("
<a href=""" & SavePath & "\" & f.name & """ Title=""" & f.name & """>" & f.name & "</a><br />")
Response.Write(f.name & vbNewLine)
Next

Set f = nothing
Set fo = nothing
Set fso = nothing
%>
</textarea>
<!-- #include file="Footer.asp" -->





Edit: Also with one and one you need to go to control panel->frontpage and edit file permissions. Give the folder write permissions for the internet user account.


[edited by - Jason Zelos on May 8, 2004 9:14:38 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.