Upload file to remote server

By QuickStep on Oct 21, 2004

Usage /upload , read the information in the script.

/*
How the script is currently configured it works like this (EXAMPLE):
-The user types '/upload test.exe' (test.exe is in the mirc dir)
-The script will submit the file to www.google.com/upload.php
-The php file will move the file 'test.exe' to the dir 'upload/'
-The file can be found at 'www.google.com/upload/test.exe'
-This is an example

-- CONTENT OF THE PHP FILE NAMED 'upload.php' (remember the mirc script must point to this file --
<?php
//Set uploaddir, remember that for that folder you must set read+write permission,
//look for the command CHMOD and set the permissions in the folder to '777'
$uploaddir = "upload/";

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

alias upload {

  ;-- Set these variables --
  %hostofphpfile = www.google.com
  %locationofphpfile = /upload.php
  ;-------------------------

  %dest = $$1-
  if ((!$file(%dest)) || ($isdir(%dest))) return
  .remove upload.tmp
  echo -a Uploading file %dest $+ ....
  sockopen upload %hostofphpfile 80
}
On *:sockopen:upload:{

  var %b = $md5() | write -c upload.tmp $+(--,%b,$lf,$&
    Content-Disposition: form-data; name="uploadfile";,$&
    filename=",$nopath(%dest),",$lf,$lf)
  .copy -a " $+ %dest $+ " upload.tmp
  write upload.tmp -- $+ %b

  var %write = sockwrite -tn upload
  %write POST %locationofphpfile HTTP/1.1
  %write Host: %hostofphpfile
  %write Connection: close
  %write Content-Type: multipart/form-data; boundary= $+ %b
  %write Content-Length: $file(upload.tmp)
  %write
  .fopen upload upload.tmp
}

On *:sockwrite:upload:{
  if $sock(upload).sq > 8192 || !$fopen(upload) { return }
  if $fread(upload,8192,&a) {
    sockwrite upload &a
  }
  else .fclose upload
}

On *:sockread:upload:{
  var %temp
  sockread %temp
  if & 2* iswm %temp {
    echo 3 -a SUCCESS!
  }
  elseif & 4* iswm & temp {
    echo 4 -a FAILED!
  }
}

On *:sockclose:upload:cleanupload
alias cleanupload {
  .sockclose upload
  if $fopen(upload) { .fclose upload }
  unset %dest
  .remove upload.tmp
}

Comments

Sign in to comment.
explodedk   -  Apr 10, 2010

i know this is old script but it almost fit my needs. great job on it...

o have a small problem when uploading a file when a file with the same name already exist...

what i want to do is overwrite the previous file always...

i am trying to upload a file called tv.csv and when i upload, it should overwrite that file...

is this posible...

 Respond  
spermis   -  Jan 12, 2009

I think you should edit this script so you can set like max filesize and file types allowed, or else this isnt secure at all.

 Respond  
guest598594   -  Oct 23, 2007

i would put a $$?=\"input\" or a $input() to ask for the things u have to set when u /upload

 Respond  
QuickStep   -  Feb 08, 2006

man it seems like ages ago since I wrote this. The advantage of doing it like this is that it will always work if the webserver is up (I had problems doing it the FTP way, sometimes it would work, and sometimes the FTP server would mess up), and you can configure the php file to perform certain tasks on the file. On the other hand the ftp method of uploading is easier.

 Respond  
Hawkee   -  Feb 05, 2006

Actually, this script interfaces with the PHP script to make the upload happen. You need the PHP script to write the file to the server and place it in your upload folder. The mIRC script just sends the file to the PHP script.

 Respond  
Yoinx   -  Feb 05, 2006

you cant just upload to a webserver... you\'d need a page to upload (the php file) or a ftp server.

(I believe)

 Respond  
d-block   -  Feb 05, 2006

can we just have it uploaded on a web server instead of a .php file?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.