Click to See Complete Forum and Search --> : Upload file from command line :> www.mysite.com/upload.php? file=x.x & dirUp=/temp


albusorin
October 22nd, 2004, 04:23 AM
Hello!
I try to upload a file from command line like this:
"www.mysite.com/upload.php? file=x.x & dirUp=/temp"
for an vb application, where I have a button and 2 parameters, witch are the file and the directory where i'm gonna put the file on the server
I don't know how to put the file into the php code.

<?
$file=$_GET['file'];
$uploaddir=$_GET['dirUp'];

move_uploaded_file($_FILES[&file]['tmp_name'],$uploaddir.'/'.$_FILES[&file]['name']);
?>

BUT it does't work

visualAd
November 20th, 2004, 06:31 PM
You seem to be mis guided as to how a file upload works. If you are manually making the request from your visualbasic application then you will need to actually send the file data yourself to the uploade script.

The best way to upload a file to a PHP script is to use the HTTP post method (ma method where the client initializes the transfer of data to a server). This can be done in visual basic using winsock. You will also need to encode your file (especially if it contains binary data) to make it safe to send over the internet via HTTP. The most commonly used being URL encoding.

Heres a couple of articles on the subject to get you going:

http://www.cs.tut.fi/~jkorpela/forms/methods.html
http://www.w3.org/Protocols/HTTP/Object_Headers.html
http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

Now the PHP application (upload.php) which recieves your file can then move the uploaded file, if you have sent it propery:

<?php
$uploaddir=$_GET['dirUp'];

move_uploaded_file($_FILES[$file]['tmp_name'],$uploaddir.'/'.$_FILES[$file]['name']);
?>

albusorin
November 22nd, 2004, 02:19 AM
Thanks 4 the help!