par
chaima » 26 août 2015, 12:22
Voila c'est ce que j'ai voulu faire un script en PHP qui me permet de faire ça ! de faire le lien entre les deux sans le faire manuellement à chaque fois ! donc avez vous une idée par quoi commencer pour développer ce script ?
ce code permet le telechargement d'un fichier depuis son url mais comment le mettre directement dans l'FTP via un script bien sur :
Code : Tout sélectionner
<?php
function download_remote($url , $save_path)
{
$f = fopen( $save_path , 'w+');
$handle = fopen($url , "rb");
while (!feof($handle))
{
$contents = fread($handle, 8192);
fwrite($f , $contents);
}
fclose($handle);
fclose($f);
}
?>
I find his one too but I'm really confused
Code : Tout sélectionner
<?php
$login_url = 'http://www.somesite.com/login.php';
//These are the post data username and password
$post_data = 'username=someusername&password=somepassword';
//Create a curl object
$ch = curl_init();
//Set the useragent
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );
//This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 );
//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Execute the action to login
$postResult = curl_exec($ch);
?>
Voila c'est ce que j'ai voulu faire un script en PHP qui me permet de faire ça ! de faire le lien entre les deux sans le faire manuellement à chaque fois ! donc avez vous une idée par quoi commencer pour développer ce script ?
ce code permet le telechargement d'un fichier depuis son url mais comment le mettre directement dans l'FTP via un script bien sur :
[code]<?php
function download_remote($url , $save_path)
{
$f = fopen( $save_path , 'w+');
$handle = fopen($url , "rb");
while (!feof($handle))
{
$contents = fread($handle, 8192);
fwrite($f , $contents);
}
fclose($handle);
fclose($f);
}
?>[/code]
I find his one too but I'm really confused
[code]<?php
$login_url = 'http://www.somesite.com/login.php';
//These are the post data username and password
$post_data = 'username=someusername&password=somepassword';
//Create a curl object
$ch = curl_init();
//Set the useragent
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );
//This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 );
//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Execute the action to login
$postResult = curl_exec($ch);
?>[/code]