I wrote the screep below to download fime from HTTP to my server using 'cURL'.
The script starts just fine, just Stop working in the middle.
I would be more then happy if you could check my code, and advice me where sould I look.
Thanks guys...
Code: Select all
<?php
set_time_limit(0);
ignore_user_abort(true);
include('http_functions.php');//-- -> just file size function and some folder removing stuff ...
include("../Pages/Includes/functions.php"); // ---> this is some file and db function, not relevant either
$_GET['file'] = str_replace("*", "&", $_GET['file']);
$_GET['file'] = str_replace("^", "?", $_GET['file']);
$totalsize=remote_file_size($_GET['file']);
$totalsize=remote_file_size($_GET['file']);
$ch = curl_init($_GET['file']);
$filename = explode('/',$_GET['file']);
$i=0;
while ( $filename[$i] != null){
$newfile = $filename[$i];
if($filename[$i] == 'http:')
$i = $i+2;
else
$i = $i+1;
}
mkdir('../../tmp/http_temp/'.$_GET[ses], 0700);
$log = fopen('../../tmp/http_temp/'.$_GET[ses].'/error.fdb', "w");
if($totalsize < 20*1024*1024)
{ file_put_contents('../../tmp/http_temp/'.$_GET[ses].'/error.fdb', '1');
}else if($totalsize > 2000*1024*1024)
{
file_put_contents('../../tmp/http_temp/'.$_GET[ses].'/error.fdb', '2');
}else if(strlen(strlen($_GET['file']) < 10 || $_GET['file']) > 150 )
{
file_put_contents('../../tmp/http_temp/'.$_GET[ses].'/error.fdb', '3');
} else{
$newfile = rand(0,999)."_".$newfile;
$fp = fopen('../../tmp/http_temp/'.$_GET[ses].'/'.$newfile, "w");
function curl_progress_callback($totalsize,$uploaded=0,$ch, $d=0) {
$percent= $uploaded/$totalsize*100;
session_start();
$_SESSION[$_GET['ses'].'percent'] = number_format($percent, 0, '', ''); // update session var
$_SESSION[$_GET['ses'].'totalsize'] = $totalsize/1024/1024;
$_SESSION[$_GET['ses'].'uploaded'] = $uploaded/1024/1024;
$_SESSION[$_GET['ses'].'speed'] = $time;
$time=1;
session_commit();
}
curl_setopt($ch,CURLOPT_HTTPHEADER,array('host: localhost:8177'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('accept-charset: windows-1255,utf-8;q=0.7,*;q=0.3'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('accept-encoding: gzip,deflate,sdch'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('accept-language: he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('cache-control: max-age=0'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('cookie: JSESSIONID=191F4E74ECC157D5F11762ACDCB50F9D; __utma=135980773.1961686238.1297530455.1297530455.1297530455.1; __utmc=135980773; __utmz=135980773.1297530455.1.1.utmccn=(organic)|utmcsr=google|utmctr=how+to+check+my+headers|utmcmd=organic; __utmb=135980773'));
curl_setopt($ch,CURLOPT_HTTPHEADER,array('user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13'));
//curl_setopt($ch,CURLOPT_HTTPHEADER,array('x-forwarded-host: fs2d1.upload-il.com'));
//curl_setopt($ch,CURLOPT_HTTPHEADER,array('x-forwarded-server: fs2d1.upload-il.com'));
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'curl_progress_callback');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
//----------------write to DB----------------------//
$formatted_file_size=round($totalsize/1024/1024);
$formatted_file_size .=" MB";
$file_name = $newfile;
$date = date("d.m.Y");
$cont_users = FileOpen("../APanel/DB/DB_Users.fdb");
$cont_usersN = explode("|", $cont_users);
$cont_users = explode("|", $cont_users);
$id=0;
$counter=0;
$renewcontent = NULL;
if(isset($_COOKIE[$set[cookie]."_Logedin"]))
{
while($cont_users[$counter] != null )
{
$cont_users[$counter] = explode("$", $cont_users[$counter]);
if($cont_users[$counter][1] == $_COOKIE[$set[cookie]."_Logedin"] )
{
$id=$cont_users[$counter][0];
$cont_users[$counter][4] = $cont_users[$counter][4]+1;
$cont_usersN[$counter] = $cont_users[$counter][0]."$".$cont_users[$counter][1]."$".$cont_users[$counter][2]."$".$cont_users[$counter][3]."$".$cont_users[$counter][4]."$".$cont_users[$counter][5]."$".$cont_users[$counter][6]."$".$cont_users[$counter][7];
}
$renewcontent = $renewcontent.$cont_usersN[$counter]."|";
$counter++;
}
}
else if($id == 0)
{
$counter=0;
while($cont_users[$counter] != null )
{
if($counter == 0)
{
$cont_users[0] = explode("$", $cont_users[0]);
$cont_users[0][4] = $cont_users[0][4]+1;
$cont_usersN[0] = $cont_users[0][0]."$".$cont_users[0][1]."$".$cont_users[0][2]."$".$cont_users[0][3]."$".$cont_users[0][4]."$".$cont_users[0][5]."$".$cont_users[0][6]."$".$cont_users[0][7];
}
$renewcontent = $renewcontent.$cont_usersN[$counter]."|";
$counter++;
}
}
FilePutContent("../APanel/DB/DB_Users.fdb",$renewcontent);
$content = FileOpen("../APanel/DB/DB_Files.fdb");
$content2 = explode("|", $content);
$counter=0;
while($content2[$counter] !=null)
{
$content2[$counter] = explode("$", $content2[$counter]);
$counter++;
}
$NewContent = NULL;
$NewContent = $content.$counter."$".$file_name."$".$formatted_file_size."$".$date."$-$0$".$id."|";
FilePutContent("../APanel/DB/DB_Files.fdb",$NewContent);
$user_DB = FileOpen("../APanel/DB/DB_Users/".$id.".fdb");
$user_DB = $user_DB.$counter."$".$file_name."$".$formatted_file_size."$".$date."$-$0|";
FilePutContent("../APanel/DB/DB_Users/".$id.".fdb",$user_DB);
$unlencrypt = new Encryption;
$filedownlink=$unlencrypt->encode(base64_encode($counter));
session_start();
$_SESSION[$_GET['ses'].'finish'] ="
<span class=advhead>העלאה הושלמה!</span><br>
<span class=advtxt>
<script type=\"text/javascript\">
function select_all(field)
{
var text_val=eval(\"document.select.\"+field);
text_val.focus();
text_val.select();
}
</script>
<form name=select>
<table width=400 border=0 align=right >
<tr class=advtxt>
<td width=25 ><b>שם :</b></td><td>$file_name</td>
</tr>
<tr class=advtxt>
<td width=25><b>גודל:</b></td><td>$formatted_file_size</td>
</tr>
</table>
</span>
<br>
<table width=600 align=center >
<tr>
<td class=advtxt><b>קישור להורדה:</b></td>
</tr>
<tr>
<td align=left>
<input name=link type=text size=75 style='text-align:left;' class=filelink readonly value='http://www.upnload.co.il/$filedownlink' >
</td>
<td VALIGN=MIDDLE>
<input style=\"vertical-align:center;\" type=button onClick=\"select_all('link');\" value=סמן class=blue>
</td>
</tr>
<tr>
<td class=advtxt ><b> קישור הורדה לפורום:</b></td>
</tr>
<tr VALIGN=MIDDLE>
<td align=left valign=center>
<textarea name=link2 rows=4 cols=77 style='text-align:left;border-color: #395692;background-color: #ecedf0;color: #395692;font-size:14px;font-family: arial;' align=left readonly class=filelink>
[URL=http://www.upnload.co.il/$filedownlink]
$file_name
[/URL]
</textarea>
</td>
<td VALIGN=MIDDLE>
<input style=\"vertical-align:center;\" type=button onClick=\"select_all('link2');\" value=סמן class=blue>
</td>
</tr>
</table>
</form>
";
rename('../../tmp/http_temp/'.$_GET[ses].'/'.$newfile , '../../U_HDD1/'.$newfile);
$dirname = '../../tmp/http_temp/'.$_GET['ses'];
close($dirname);
}
session_commit();
?>