PDA

View Full Version : سوال: دانلود فایل با سرور



darkface
یک شنبه 10 دی 1391, 12:28 عصر
سلام خسته نباشید
من میخوام فایل ها را روی سرور های دیگه بکشم روی سرور خوردم چی کار باید بکنم؟؟
این کد هم نوشتم ولی کار نمیده


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome To MyUploader</title>
<style>
.body{
backgrand:black;
}

</style>
</head>

<body text="#FFFFFF">
<div id="main">
<center>
<br /><br />
<form action="" method="post" enctype="multipart/form-data">
<font color="black">لینک را وارد کنید
<br/>
<input name="link1" type="text" width="550" /><br/>
<br/>
نام فایل را وارد کنید
<br/>
</font>
<input name="input1" type="text" width="350" /><br/>
<input name="sum" type="submit" />

</form>
</center>
</div>
<?php
if(isset($_POST['link1']) && isset($_POST['input1'])) {
$link1 = $_POST['link1'];
echo($link1);
$input1 = $_POST['input1'];
@copy($link1, 'file/'.$input1);
}
?>
</body>
</html>

siavashsay
یک شنبه 10 دی 1391, 14:47 عصر
شما میتونید از تابع ftp_get() برای باز کردن کی کانکشن ftp استفاده کنید :


$local_file = 'localname.zip'; // the nam $server_file = 'servername.zip'; $conn = ftp_connect($ftp_server); $login_result = ftp_login($conn, $ftp_user_name, $ftp_user_pass); if (ftp_get($conn, $local_file, $server_file, FTP_BINARY)) { echo "Successfully copied"; } ftp_close($conn);


و اگر میخواهید ازURL دانلود کنید :


$fullPath = "filepath.pdf"; if ($fd = fopen ($fullPath, "r")) { $fsize = filesize($fullPath); $path_parts = pathinfo($fullPath); $ext = strtolower($path_parts["extension"]); header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); header("Content-length: $fsize"); header("Cache-control: private"); //use this to open files directly while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } fclose ($fd);

منبع : http://stackoverflow.com/questions/9843933/copy-file-from-remote-server-or-url