steviez Posted August 21, 2007 Share Posted August 21, 2007 Hi guys, I need some help with my code if you can please.... Here is the story, I need to make my file hosting site upload to a remote server (or servers) and then the file be retrieved from that server upon download. Here is my code so far: <?php require_once("admin/config.php"); include("login_database.php"); include("login.php"); require_once("conn.php"); require_once("functions.php"); //This is our limit file type condition $arr_value = array('text/php','mpeg','etc'); if(in_array($_FILES["fupload"]["name"] ,$arr_value)){ alert("No PHP Files"); goto(SITE_URL); } if($_REQUEST['human_check'] != $_SESSION['human_check_code']){ alert("Human verification failed. Please try again and enter verification code correctly."); goto(SITE_URL); exit(); } if($_FILES["fupload"]["size"] <= (MAX_SIZE*1048576)) { $_SESSION['key'] = randomNumber(); $_SESSION['del_key'] = randomNumber(); $strSql = "select * from xl_files where `key` = '".$_SESSION['key']."'"; $strSql2 = "select * from xl_files where `del_key` = '".$_SESSION['del_key']."'"; $rsChkKey = $conn->execute($strSql); $rsChkKey2 = $conn->execute($strSql2); if(!$rsChkKey->EOF){ while($rsChkKey->fields['key'] == $_SESSION['key']){ $strSql = "select * from xl_files where `key` = '".$_SESSION['key']."'"; $rsChkKey = $conn->execute($strSql); $_SESSION['key'] = randomAlphaNumeric(; } } if(!$rsChkKey2->EOF){ while($rsChkKey2->fields['del_key'] == $_SESSION['del_key']){ $strSql2 = "select * from xl_files where `del_key` = '".$_SESSION['del_key']."'"; $rsChkKey2 = $conn->execute($strSql2); $_SESSION['del_key'] = randomAlphaNumeric(; } } $newfilename = $_FILES["fupload"]["name"]; $newfilename = preg_replace('/\s+/', ' ', $newfilename); $newfilename = ereg_replace(" ","_",$newfilename); $newfilename = ereg_replace("[^a-z,A-Z,0-9,_.]","_",$newfilename); $newfilename = preg_replace('/\_+/', '_', $newfilename); if(strlen($newfilename)>62){ $filename_array_dot = explode(".", $newfilename); $filename_array_count = count($filename_array_dot); $ext = $filename_array_dot[$filename_array_count-1]; $newfilename = substr($newfilename,0,(65-strlen($ext+1))); $newfilename = $newfilename.".".$ext; } $upload_folder = UPLOAD_FOLDER; $incr = 0; while (file_exists($upload_folder.$newfilename)){ $incr++; $newfilename = $incr."_".$newfilename; } $upload = copy($_FILES["fupload"]["tmp_name"], $upload_folder.$newfilename); if(!$upload) { echo "error in uploading..."; } else { $strSql = "INSERT INTO `xl_files` ( `fileid` , `key` , `del_key` , `mailto` , `mailfrom` , `mailmessage` , `filename` , `foldername`, `filesize` , `username`, `uploadtime` , `ip`, `downloads`) VALUES ( '', '".$_SESSION['key']."', '".$_SESSION['del_key']."', '".$_REQUEST['mailto']."', '".$_REQUEST['mailfrom']."', '".$_REQUEST['message']."', '$newfilename', '$upload_folder', '".$_FILES["fupload"]["size"]."', '".$_SESSION['username']."', '".time()."', '".$_SERVER['REMOTE_ADDR']."', '0')"; $conn->execute($strSql); if(empty($_REQUEST['mailto'])){ $mailto = "none"; }else{ $mailto = $_REQUEST['mailto']; } $strSql = "select * from ".DB_TABLE_PREFIX."template_emails where email_id = '1001'"; $rsMail = $conn->execute($strSql); $strMessage = $rsMail->fields['email_matter']; $strMessage = ereg_replace(chr(13),"<br>", stripslashes($strMessage)); $strMessage = ereg_replace("{filename}",$newfilename,$strMessage); $strMessage = ereg_replace("{filesize}",number_format($_FILES["fupload"]["size"]/1024,2),$strMessage); $strMessage = ereg_replace("{mailto}",$mailto,$strMessage); $strMessage = ereg_replace("{message}",ereg_replace(chr(13),"<br>",stripslashes($_REQUEST['message'])),$strMessage); $strMessage = ereg_replace("{fileurl}","<a href=".SITE_URL."/v/".$_SESSION['key']."/$newfilename>".SITE_URL."/v/".$_SESSION['key']."/$newfilename.html</a>",$strMessage); if(!empty($_REQUEST['mailfrom'])){ despatchMail($mailfrom , MAIL_FROM_NAME , ADMIN_EMAIL, $rsMail->fields['email_subject'] , ereg_replace(chr(13),"<br>",stripslashes($strMessage))); } $strSql = "select * from ".DB_TABLE_PREFIX."template_emails where email_id = '1000'"; $rsMail = $conn->execute($strSql); $strMessage = $rsMail->fields['email_matter']; $strMessage = ereg_replace(chr(13),"<br>", stripslashes($strMessage)); $strMessage = ereg_replace("{filename}",$newfilename,$strMessage); $strMessage = ereg_replace("{filesize}",number_format($_FILES["fupload"]["size"]/1024,2),$strMessage); $strMessage = ereg_replace("{mailfrom}",$mailfrom,$strMessage); $strMessage = ereg_replace("{message}",ereg_replace(chr(13),"<br>",stripslashes($_REQUEST['message'])),$strMessage); $strMessage = ereg_replace("{fileurl}","<a href=".SITE_URL."/v2/".$_SESSION['key']."/$newfilename>".SITE_URL."/v2/".$_SESSION['key']."/$newfilename.html</a>",$strMessage); if(!empty($_REQUEST['mailto'])){ sendMail($_REQUEST['mailto'], MAIL_FROM_NAME, $mailfrom , $rsMail->fields['email_subject'], ereg_replace(chr(13),"<br>",stripslashes($strMessage))); } } // Send message to admin $to = "admin@".EMAIL_URL.""; $subject = "New File Uploaded!"; $message = " <html> <head> <title>New File Uploaded</title> </head> <body> <p>This is an automated message to tell you that a new file has been uploaded to your site, Bellow are the file details:<br></p> <P>File Name: ".$newfilename."<br> File Size: ".number_format($_FILES["fupload"]["size"]/1024,2)." KB<br> Uploaders IP: ".$_SERVER['REMOTE_ADDR']."<br> </p> <p>Please check the file to make sure it complies with the terms of service!<br/><br/> Best regards,<br/> Your Server </p> </body> </html> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: <newfile@'.EMAIL_URL.'>' . "\r\n"; mail($to,$subject,$message,$headers); goto("success.php"); }else{ $_SESSION['key'] = ""; alert("File size exceeds the maximum allowed limit."); goto("index.php"); } ?> An i was told to use this code to make remote uploads work: $file = "testfile.txt"; $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://example.com/putscript"); curl_setopt($c, CURLOPT_USERPWD, "username:password"); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_PUT, true); curl_setopt($c, CURLOPT_INFILESIZE, filesize($file)); $fp = fopen($file, "r"); curl_setopt($c, CURLOPT_INFILE, $fp); curl_exec($c); curl_close($c); fclose($fp); I have tried everything to make this work and i am not getting anywhere, please someone help! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/66023-solved-help-with-uploads-please/ Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Share Posted August 21, 2007 why don't you take a shot at the freelancing forum Quote Link to comment https://forums.phpfreaks.com/topic/66023-solved-help-with-uploads-please/#findComment-330207 Share on other sites More sharing options...
steviez Posted August 21, 2007 Author Share Posted August 21, 2007 is it that hard to do? Quote Link to comment https://forums.phpfreaks.com/topic/66023-solved-help-with-uploads-please/#findComment-330216 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.