flat assembler
Message board for the users of flat assembler.

Index > Windows > Upload file via php

Author
Thread Post new topic Reply to topic
seth0x2b



Joined: 02 Dec 2006
Posts: 8
seth0x2b 08 Dec 2006, 14:00
Hey guys...
What I would like to do is this:

Upload a file via a php script on my server, without using ftp...
This would be the html version of what I want to do...

Code:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
    


and the php script:

Code:
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
    


I haven't tested it but it seems just about right...

I would apreciate any help or advice I can get
Thanks in advance
Post 08 Dec 2006, 14:00
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 08 Dec 2006, 15:09
Now how does this have anything at all to do with FASM, or Windows?
Post 08 Dec 2006, 15:09
View user's profile Send private message Reply with quote
WytRaven



Joined: 08 Sep 2004
Posts: 45
Location: Canberra, Australia
WytRaven 08 Dec 2006, 15:20
Code:
echo "There was an error processing this post, please try again!";    

_________________
All your opcodes are belong to us
Post 08 Dec 2006, 15:20
View user's profile Send private message Reply with quote
seth0x2b



Joined: 02 Dec 2006
Posts: 8
seth0x2b 08 Dec 2006, 15:25
UCM wrote:
Now how does this have anything at all to do with FASM, or Windows?


I want to achieve this from inside a program compiled with FASM, and the program will have a GUI..so it'll run on Windows...

I thought it would be obvious since i posted on this part of the forum...my bad..

Cheers
Post 08 Dec 2006, 15:25
View user's profile Send private message Reply with quote
seth0x2b



Joined: 02 Dec 2006
Posts: 8
seth0x2b 12 Dec 2006, 23:28
I managed to get the upload done with the FtpPutFile API..but I did it with masm32
When I tried "converting" to FASM, I get errors because it can't find the API variables used to connect to the server("INTERNET_OPEN_TYPE_PRECONFIG" would be one of them...)
This might be because masm has a wininet.lib included..and FASm hasn't..

MASM:
Code:
Include wininet.inc
IncludeLib      wininet.lib

.Data
appName DB 'Caller', 0
FTPAddress DB 'server', 0
Username DB 'user', 0
Password DB 'pass', 0

localFile DB 'C:\WINDOWS\Zapotec.bmp', 0
remoteFile DB 'Zapotec.bmp', 0

hInternet HANDLE ?
hConnect HANDLE ?

.Code
start:

Invoke InternetOpen, Addr appName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0
Mov hInternet, Eax

Invoke InternetConnect, hInternet, Addr FTPAddress, INTERNET_DEFAULT_FTP_PORT, Addr Username, Addr Password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0
Mov hConnect, Eax

Invoke FtpPutFile, hConnect, Addr localFile, Addr remoteFile, FTP_TRANSFER_TYPE_BINARY, 0

Invoke InternetCloseHandle, hConnect
Invoke InternetCloseHandle, hInternet

Invoke ExitProcess, Eax

End start
    




FASM:
Code:
format pe gui 4.0
entry start

include '%finc%\win32a.inc'


section ".data" data readable writeable

appName DB 'Caller', 0
FTPAddress DB 'server', 0
Username DB 'user', 0
Password DB 'pass', 0

localFile DB 'C:\WINDOWS\Zapotec.bmp', 0
remoteFile DB 'Zapotec.bmp', 0

hInternet dd ?
hConnect dd ?



section ".code" data readable writeable

start:

push 0
push 0
push 0
push 0 ;INTERNET_OPEN_TYPE_PRECONFIG
push appName
call InternetOpen
;Invoke InternetOpen, Addr appName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0
Mov [hInternet], Eax

push 0
push INTERNET_FLAG_PASSIVE
push INTERNET_SERVICE_FTP
push Password
push Username
push INTERNET_DEFAULT_FTP_PORT
push FTPAddress
push hInternet
call InternetConnect

;Invoke InternetConnect, hInternet, Addr FTPAddress, INTERNET_DEFAULT_FTP_PORT, Addr Username,
; Addr Password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0
Mov [hConnect], Eax


push 0
push FTP_TRANSFER_TYPE_BINARY
push remoteFile
push localFile
push hConnect
call FtpPutFile
;Invoke FtpPutFile, hConnect, Addr localFile, Addr remoteFile, FTP_TRANSFER_TYPE_BINARY, 0

push hConnect
call InternetCloseHandle
;Invoke InternetCloseHandle, hConnect

push hInternet
call InternetCloseHandle
;Invoke InternetCloseHandle, hInternet

call Exitprocess
;Invoke ExitProcess, Eax


section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
wininet,'WININET.DLL'

import kernel32,\
ExitProcess,'ExitProcess'

import wininet,\
InternetOpen,'InternetOpenA',\
InternetConnect,'InternetConnectA',\
FtpPutFile,'FtpPutFileA',\
InternetCloseHandle,'InternetCloseHandleA'   
    


I'll apreciate any feedback
Thanks in advance. Cheers
Post 12 Dec 2006, 23:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Dec 2006, 23:51
fasm has "invoke" too, though, note that "Invoke" is different to "invoke" Wink

About the constant, add it by your self. I usually extract from masm packages some constants that fasm packages lacks of.
Post 12 Dec 2006, 23:51
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 13 Dec 2006, 00:03
seth0x2b, the fasm defines are ones Tomasz has added, probably from C headers, if one is missing, define it yourself.

_________________
redghost.ca
Post 13 Dec 2006, 00:03
View user's profile Send private message AIM Address MSN Messenger Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 13 Dec 2006, 05:49
You can look on my website and get some extra includes: http://users.egl.net/talktomatt/default.html
Post 13 Dec 2006, 05:49
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.