Log in

View Full Version : upload script help



wibumba
06-29-2006, 08:16 AM
Hello,

I'm curently trying to develop a certain program (C++) that requires the uploading of the user's log file. I don't know php, but I do know html. My buddy made me an upload file script in php, but to use it to upload, I would have to either directly give out my upload site (which I don't want), or simulate program keystrokes and mousclicks to manually upload, which is not only a huge pain, but defective and freaky for the user. I don't know much about php, but I noticed that sometimes they refer to some kind of variable name in the url, for example:
"http://www.myexample.com/index.php?user=me"

Would it be possible to make a script where the filepath to upload can be defined by the url? Maybe like this:
"http://www.wibumbasoft.tk/upload.php?filetoupload=C:\example.txt"

That way my program can use
"Run, http://www.wibumbasoft.tk/upload.php?filetoupload=%savepath%"
"%savepath%" being the defined path of the file to upload.

If there is any other way of accomplishing this without interacting with the page itself, maybe using another language, that would be great. Thanks.

djr33
06-29-2006, 05:12 PM
Those are called GET variables in php. (As opposed to POST... the two ways form data can be sent.)

$_GET['varname'] will be that value.
EX:
index.php?var=value
$_GET['var'] is "value".


Now... the issue will be that, due to security, the user may need to actually select the file themselves. I wonder, though.
Might also depend on the OS the person is using.

Maybe just try this simple code on a php page, where you use page.php?file=PATH to set which file. See if it seems to work.

<input type="file" value="<?php echo $_GET['file'];>">
With just that, you should be able to tell if the file was selected... it would be like if you used the browse button to choose the file, except like you had already done that, or something.

(To actually use that in a form, you'd need more stuff, not to mention the page that actually uploads the file, but, yeah, that will see if it's worth going farther.)

Twey
06-29-2006, 05:38 PM
No, you're on completely the wrong track. The path of the file need never be sent to the server. The file itself is sent; the server doesn't somehow reach into the client's hard drive and pluck the file from the specified place.

You send POST data directly in the request. The request format is:
POST /path/to/file.php HTTP/1.1
Host: mysite.com
Content-Type: multipart/form-data; boundary=---------------------------15415454588765403441079621624
Content-Length: 254

-----------------------------15415454588765403441079621624
Content-Disposition: form-data; name="ufile"; filename="filename.fil"
Content-Type: application/octet-stream

Content goes here
-----------------------------15415454588765403441079621624--

That boundary can be anything. It's usually randomly generated. The lines are, of course, seperated by 13,10.

Which socket library are you using?

wibumba
06-29-2006, 08:39 PM
Sorry man, but I don't know any php. And I really don't know what a socket library is.

djr33
06-29-2006, 08:44 PM
Twey, wouldn't what I'm saying work, in the sense that it would open a page that would have an "upload" button that would then work based on the chosen file?

Clearly it's not perfect... and what you're suggesting shortcuts a bunch, so it's probably better. But... would it not work?

Twey
06-29-2006, 08:46 PM
djr33: No, the problem is that s/he wanted it done automatically, without user intervention.

wibumba: I didn't use any PHP :) I was just outlining how to perform POST requests, which can then be used with any socket-enabled language (probably C++ in your case). A socket library is a library that wraps kernel socket functions, such as UNIX sockets, winsock, or a more abstracted library like Qt sockets.

djr33
06-29-2006, 08:54 PM
Right, but you could use that, add a javascript function to automatically send the form when it loads, and there you go. You'd need to have the page open anyway for the time it takes to transfer the file to the server.

If the second solution will work, that's better. The first is a fairly simple way to cheat, though. heh.

Twey
06-29-2006, 09:01 PM
You'd need to have the page open anyway for the time it takes to transfer the file to the server.We're trying not to involve pages here :)

djr33
06-29-2006, 09:04 PM
Ah. That's better... if it works :)