nikec Posted June 2, 2008 Share Posted June 2, 2008 Hi guys, I'm trying to create a script that allows you to remote upload a file from your server, can somebody help me out, this is what I already have <?php set_time_limit(0); login('username', 'password'); echo upload(); function login($username, $password) { $post_fields = array_to_http(array( // Generate post string 'nickname' => $username, 'password' => $password, 'action' => 'login', )); $ch = curl_init(); curl_setopt ( $ch, CURLOPT_URL, 'http://www.megavideo.com/?s=signup' ); curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_fields ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $ch, CURLOPT_HEADER, false ); curl_setopt ( $ch, CURLOPT_COOKIE, 'test.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEJAR, 'test.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEFILE, 'test.txt' ); $result = curl_exec ( $ch ); curl_close ( $ch ); // Close connection } function upload() { echo $file = getcwd().'\\file.avi'; $post_fields = array_to_http(array( // Generate post string 'title' => 'testtitle', 'description' => 'testdescription', 'action' => 'step2', 'tags' => 'testtags', 'language' => '1', 'channel' => '24', )); $ch = curl_init(); curl_setopt ( $ch, CURLOPT_URL, 'http://megavideo.com/?c=upload' ); curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_fields ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $ch, CURLOPT_HEADER, false ); curl_setopt ( $ch, CURLOPT_COOKIE, 'test.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEJAR, 'test.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEFILE, 'test.txt' ); curl_setopt ( $ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); echo $result = curl_exec ( $ch ); $post_fields = array_to_http(array( // Generate post string 'title' => 'testtitle', 'description' => 'testdescription', 'action' => 'submit', 'tags' => 'testtags', 'language' => '1', 'channel' => '24', 'file' => '@$file', )); curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_fields ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $ch, CURLOPT_HEADER, false ); curl_setopt ( $ch, CURLOPT_COOKIE, 'test.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEJAR, 'test.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEFILE, 'test.txt' ); curl_setopt ( $ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $result = curl_exec ( $ch ); echo $result; } function array_to_http($array) { $retvar = ''; while(list($field, $data )= @each($array)) { $retvar .= (empty($retvar))? '':'&'; $retvar .= ($field).'='.($data); } return $retvar; } ?> Link to comment https://forums.phpfreaks.com/topic/108361-megavideo-upload/ Share on other sites More sharing options...
trq Posted June 2, 2008 Share Posted June 2, 2008 What is the problem? Link to comment https://forums.phpfreaks.com/topic/108361-megavideo-upload/#findComment-555496 Share on other sites More sharing options...
nikec Posted June 2, 2008 Author Share Posted June 2, 2008 I can't figure out how to do the last step of the uploading, because you must select a file and that is where i get stuck, how can you select a file on your server through a <input type="upload" ... /> ? Link to comment https://forums.phpfreaks.com/topic/108361-megavideo-upload/#findComment-555521 Share on other sites More sharing options...
BlueSkyIS Posted June 2, 2008 Share Posted June 2, 2008 make sure you enctype set on your <FORM> <FORM METHOD='POST' ACTION='<?=$_SERVER['PHP_SELF'];?>' name='aform' ID='aform' ENCTYPE='multipart/form-data'> <input type="file" name='somefile' size='30'/> <INPUT TYPE='submit' VALUE='Upload File'> </FORM> Link to comment https://forums.phpfreaks.com/topic/108361-megavideo-upload/#findComment-555546 Share on other sites More sharing options...
nikec Posted June 3, 2008 Author Share Posted June 3, 2008 No, that is not what I'm looking for, this code is client side, I want to upload something to megavideo that is on my server. Link to comment https://forums.phpfreaks.com/topic/108361-megavideo-upload/#findComment-556271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.