PHP Display Image (SSL PROXY) - php

I am trying to make a PHP script that accepts a URL and displays it (trying to keep SSL on my project)
However, I am unable to get anything to output with my script. No errors are being displayed and I am at a loss of words. What am I not seeing?
<?php
//if parameter is empty
if((!isset($_GET['img'])) or ($_GET['img'] == '') or (!isset($per['scheme'])))
{
exit;
}
$per = parse_url($_GET['img']);
print_r ($per);
$imgurl = $_GET['img'];
print_r ($imgurl);
$imgurl = str_replace(' ', "%20", $imgurl);
$aFile = getimagesize($imgurl);
print_r ($aFile);
//check file extension
if($aFile == 'jpg' or $aFile == 'jpeg'){
header('Content-Type: image/jpeg');
imagejpeg(getimg($file));
} elseif($aFile == 'png') {
header('Content-Type: image/png');
imagepng(getimg($file));
} elseif($aFile == 'gif') {
header('Content-Type: image/gif');
imagegif(getimg($file));
} else {
die('not supported');
}
$imgurl = $_GET['img'];
$imgurl = str_replace(' ', "%20", $imgurl);
function getimg($imageurl) {
$cache_expire = 60*60*24*365;
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg, image/png';
$headers[] = 'Cache-Control: maxage=. $cache_expire';
$headers[] = 'Pragma: public';
$headers[] = 'Accept-Encoding: None';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
$process = curl_init($imageurl);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_REFERER, $_GET['img']);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_HTTPGET, true);
curl_setopt($process, CURLOPT_USERAGENT, $user_agent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
exit;
?>
Here is an edited version of the script that outputs garbled text when I use readfile:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
//if parameter is empty
if((!isset($_GET['img'])) or ($_GET['img'] == ''))
{
exit;
}
$per = parse_url($_GET['img']);
$imgurl = $_GET['img'];
$imgurl = str_replace(' ', "%20", $imgurl);
$aFile = getimagesize($imgurl);
//check file extension
$checkmime = getimagesize($imgurl);
if($checkmime['mime'] != 'image/png' && $checkmime['mime'] != 'image/gif' && $checkmime['mime'] != 'image/jpeg') {
die('not supported');
} else {
readfile("$imgurl");
}
function getimg($imageurl) {
$cache_expire = 60*60*24*365;
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg, image/png';
$headers[] = 'Cache-Control: maxage=. $cache_expire';
$headers[] = 'Pragma: public';
$headers[] = 'Accept-Encoding: None';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
$process = curl_init($imageurl);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_REFERER, $_GET['img']);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_HTTPGET, true);
curl_setopt($process, CURLOPT_USERAGENT, $user_agent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
exit;
?>

If this truly is your entire script your problem first lies with $per['scheme'] not being set so it will trip the first if() statement and have the script exit.
You check if it's not set here: !isset($per['scheme']) so it will make the expression TRUE and thus end the script, reason no output even from print_r();
Use this instead:
if (empty($_GET['img'])) // Check if $_GET['img'] is not set AND is = '' (empty)
{
exit;
}
Use:
} else {
header('Content-Type: ' . $checkmime['mime']);
readfile($imgurl);
}

Related

How follow meta redirect with curl and php?

$url='http://wtion';
$headers = array(
'GET '.$url.' HTTP/1.1',
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3',
'Accept: text/html',
'Accept-Language: ru,en-us;',
'Accept-Charset: windows-1251,utf-8;',
'Connection: close');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//Массив с HTTP заголовками для передачи на сервер
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Не выводить ответ в браузер. Пусть функция пишет все в переменную.
$site=curl_exec($ch); //В случае успеха - html тест запрошенной страницы. Иначе - false
curl_close($ch);
echo $site;
After running the code , I get this line
<meta http-equiv='Refresh' content='0; url=/animation.php'>
How can I follow the redirect and get the response of /animation.php?
Curl cannot follow a meta refresh. Use DOMXml to parse the curl response as long as it's valid, you can check for a refresh return, then process the refresh path appropriately.
$url='http://wtion';
$headers = array(
'GET '.$url.' HTTP/1.1',
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3',
'Accept: text/html',
'Accept-Language: ru,en-us;',
'Accept-Charset: windows-1251,utf-8;',
'Connection: close');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//Массив с HTTP заголовками для передачи на сервер
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Не выводить ответ в браузер. Пусть функция пишет все в переменную.
$site=curl_exec($ch); //В случае успеха - html тест запрошенной страницы. Иначе - false
curl_close($ch);
$xml = simplexml_load_file($site);
$result = $xml->xpath("//meta[#http-equiv='refresh']");
if (!empty($result)) {
... do stuff to get the final $site value....
}
echo $site
I found an implementation in a comment of get_meta_tags() documentation page.
function sendRequest($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'GET '.$url.' HTTP/1.1', // Are you sure about this?
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3',
'Accept: text/html',
'Accept-Language: ru,en-us;',
'Accept-Charset: windows-1251,utf-8;',
'Connection: close'
));*/
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
function getUrlContents($url, $maximumRedirections = null, $currentRedirection = 0)
{
$result = false;
$contents = sendRequest($url);
// Check if we need to go somewhere else
if (isset($contents) && is_string($contents))
{
preg_match_all('/<[\s]*meta[\s]*http-equiv="?REFRESH"?' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', $contents, $match);
if (isset($match) && is_array($match) && count($match) == 2 && count($match[1]) == 1)
{
if (!isset($maximumRedirections) || $currentRedirection < $maximumRedirections)
{
return getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection);
}
$result = false;
}
else
{
$result = $contents;
}
}
return $contents;
}
echo getUrlContents('http://wtion');

How to login with curl and get link download in other website

I have a website i want get link download from it , but this website request me login , and i create login with curl , but it not work !
this is my code
config.php
$config['id'] = 'dinhvanvu94#gmail.com'; //
$config['password'] = 'nhocmiss#2'; //
curl.php
class cURL {
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
var $proxy;
function __construct($cookies=TRUE,$cookie='cook.txt',$compression='gzip',$proxy='') {
$this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->user_agent = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36';
$this->compression=$compression;
$this->proxy=$proxy;
$this->cookies=$cookies;
if ($this->cookies == TRUE) $this->cookie($cookie);
}
function cookie($cookie_file) {
if (file_exists($cookie_file)) {
$this->cookie_file=$cookie_file;
} else {
fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
$this->cookie_file=$cookie_file;
fclose($this->cookie_file);
}
}
function getheader($url) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process,CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($process,CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($process,CURLOPT_CAINFO, NULL);
curl_setopt($process,CURLOPT_CAPATH, NULL);
$return = curl_exec($process);
curl_close($process);
return $return;
}
download.php
include('start.php');
function _login()
{
global $html, $curl, $config;
preg_match('#<input type="hidden" value="(.*?)" name="fs_csrf" />#',$html,$fs_csrf);
$data = 'fs_csrf=' . $fs_csrf[1] . '&LoginForm%5Bemail%5D=' . urlencode($config['id']). '&LoginForm%5Bpassword%5D=' . urlencode($config['password']) . '&LoginForm%5BrememberMe%5D=0&LoginForm%5BrememberMe%5D=1&yt0=%C4%90%C4%83ng+nh%E1%BA%ADp';
$curl->post('https://www.fshare.vn/login',$data);
}
$html = $curl->get('https://www.fshare.vn/file/TM5MQ3VX2T');
if(!preg_match('#<a style="cursor: pointer;color: \#999999;" title="(.*?)"#', $html, $acc))
{
// chua dang nhap
_login();
}
$link = $curl->get('https://www.fshare.vn/download/index');
echo $link;
and start.php
include('config.php');
include('curl.php');
$curl = new cURL();
This í my code and it word to login thi web but it not get link
Your email and password are not stored in the config array, they are in a comment.
$config['id'] = 'THIS IS WHERE YOU WRITE YOUR EMAIL';
$config['password'] = 'THIS IS WHERE YOU WRITE YOUR PASSWORD';
You are trying to use $curl->get() and $curl->post() in your download.php file. These methods are not defined.Is the class code written by you?

php curl not saving file to location

I have been searching for an answer for this all day, but with no luck!
I want to download/copy an image from the web to a location on my server, The code below doesn't seam to throw any errors other than the image is just not saving to the required or any directory.
As you can see I am using cURL to get the image and the variable $contents is returning true (1) so I am assuming the script works but I am actually missing something.
Many thanks in advance for your help. :-)
$dir = URL::base() . "/img/products/";
$imgSrc = "an image on the web";
$file = fopen($dir, "wb");
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$ch = curl_init($imgSrc);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file); // location to write to
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$contents = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
fclose($lfile);
if ($curl_errno > 0)
{
Log::write("CURL", "cURL Error (".$curl_errno."): ".$curl_error);
}
else
{
Log::write("CURL", "Data received: " . $contents);
}
return;
Provide the file the writing access to PHP FILE using curl to store the contents. This can be done in three ways:
If you have the terminal access then use chmod to provide the writing access
If you have the CPanel access then use directory explorer then provide the writing access to the file by changing file properties.
You must have the access to FTP and change the file access attributes and provide the writing access.
Don't use curl.
If all you need to do is download an image, go for "file_get_contents" instead.
It's dead easy:
$fileContents = file_get_contents("https://www.google.com/images/srpr/logo4w.png");
File::put('where/to/store/the/image.jpg', $fileContents);
function saveImageToFile($image_url,$output_filename)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto))
{
unlink($saveto); //Saves over files
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
Your problem is quite simple, and I have no idea how everyone else ignored it. It is Laravel-specific. Your $dir variable returns an HTTP resource identifier. What you need is a filesystem identifier.
For laravel, change your URL::to() to path("public") to tell Laravel to stop using HTTP URIs and instead take the local path to the public folder (/your/laravel/setup/path/public/).
code
$dir = path("public") . "img/products/";
$imgSrc = "an image on the web";
$file = fopen($dir . substr($imgSrc,strrpos("/",$imgSrc)+1), "wb");
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$ch = curl_init($imgSrc);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file); // location to write to
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$contents = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_errno > 0)
{
Log::write("CURL", "cURL Error (".$curl_errno."): ".$curl_error);
}
else
{
Log::write("CURL", "Data received: " . $contents);
fwrite($file,$contents);
fclose($file);
}
return;
OK, finally got it all working and here is the code if anyone else ever tries to do the same sort of thing!
I was missing these parts:
$dir = $_SERVER['DOCUMENT_ROOT'] . "/img/products/";
and
fwrite($file,$contents);
So here is my final code... credit to Sébastien for pointing me in the right direction. Thanks.
if($method == 'save')
{
$productId = Input::get('pId');
$removeProductImages = DB::table('product_ref_images')->where('product_id', '=', $productId)->delete();
$imagesData = Input::get('imageRefs');
$dir = $_SERVER['DOCUMENT_ROOT'] . "/img/products/";
$sortOrder = 0;
for ($i=0; $i < count($imagesData); $i++) {
$imgSrc = trim($imagesData[$i]['imgSrc']);
$imgId = trim($imagesData[$i]['imgId']);
$file = fopen($dir . basename($imgSrc), "wb");
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$ch = curl_init($imgSrc);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$contents = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_errno > 0)
{
Log::write("CURL", "cURL Error (".$curl_errno."): ".$curl_error);
break;
}
else
{
fwrite($file,$contents);
fclose($file);
$imageIds = DB::table('product_ref_images')->order_by('image_id', 'desc')->first();
if($imageIds == null)
{
$imageIds = 0;
}
else
{
$imageIds = $imageIds->image_id;
}
$updateImages = DB::table('product_ref_images')
->insert(array(
'image_id' => $imageIds + 1,
'product_id' => $productId,
'flickr_image_id' => $imgId,
'sort_order' => $sortOrder++,
'local_storage_url' => $dir . basename($imgSrc),
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s")
));
}
}
return Response::json('Complete');
}
Remove this line:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
You're storing the response to a file, not to the return variable. Otherwise, you have to save it yourself (like you did in the other solution).

Call to undefined function on setting referrer script

I am using this script to either set the referrer to the url or if the referrer is empty or cookie is set, hit the image.
The code below is what I have so far, the curl function part works if i put it in a file on it's own but am having trouble putting it with the cookie part.
The error is Call to undefined function geturl()
<?php
$image = 'image_url';
if($_COOKIE["6346"] == 1) {
$show = 0;
}
else {
$show = 1;
$hours = rand(24,68);
setcookie('6346', 1, time()+(60*60*$hours));
}
if (!empty($_SERVER['HTTP_REFERER'])) {
$goodreferer = 0;
}
else {
$goodreferer = 1;
}
if ($show == 1 && $goodreferer == 0) {
echo geturl('url(dot)com', 'referer(dot)com');
function geturl($url, $referer) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_REFERER, $referer);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
}
else {
header('Location: ' . $image);
exit;
}
?>
When a function is defined in a conditional manner its definition must be processed prior to being called. from the PHP Manual Conditional functions.
So try define the geturl() before its been called.
Try this SO post too Php - a function inside an if structure
You are calling the function before it's defined. Move the function to the top of the file. Also, you should not define the function in an if statement.
Don't define your function inside an if() control structure. That is a sure recipe for confusion. It's like multiple inheritance -- just because you CAN does not mean you SHOULD!
I think if you use good indenting of the control structures, you will find that your logic is easier to follow and the code is easier to debug. This version of the script works correctly.
http://www.laprbass.com/RAY_temp_user1923808.php
<?php // RAY_temp_user1923808.php
error_reporting(E_ALL);
$image = 'image_url';
if( isset($_COOKIE["6346"]) && ( $_COOKIE["6346"] == 1) )
{
$show = 0;
}
else
{
$show = 1;
$hours = rand(24,68);
setcookie('6346', 1, time()+(60*60*$hours));
}
if (!empty($_SERVER['HTTP_REFERER']))
{
$goodreferer = 0;
}
else
{
$goodreferer = 1;
}
if ($show == 1 && $goodreferer == 0)
{
echo geturl('url(dot)com', 'referer(dot)com');
}
else
{
header('Location: ' . $image);
exit;
}
function geturl($url, $referer) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_REFERER, $referer);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}

Copy images from url to server, delete all images after

I have an affiliate link with a product image
http://www.myaffiliate.com/products/product.jpg
I want to copy the imagine to my website, in a folder called lets say products. It's hosted on shared sherver, not my pc. I think the php copy() does not work, well tried it and I think my hosts doen't support the method. How can I do it, curl maybe? Then, I need a php command to delete all the images from the products folder - I'll do this with a cronjob.
<?php
$table = 'cron';
$feed = 'myfeed';
$xml = simplexml_load_file($feed);
mysql_query("TRUNCATE TABLE ".$table."", $dbh1);
mysql_query("TRUNCATE TABLE ".$table."", $dbh2);
function getimg($url) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'php';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
foreach( $xml->performerinfo as $performerinfo )
{
$performerid = $performerinfo->performerid;
$category = $performerinfo->category;
$subcategory = $performerinfo->subcategory;
$bio = $performerinfo->bio;
$turnons = $performerinfo->turnons;
$willing = $performerinfo->willingness;
$willingness = str_replace(',', ', ', $willing);
$age = $performerinfo->age;
$build = $performerinfo->build;
$height = $performerinfo->height;
$weight = $performerinfo->weight;
$breastsize = $performerinfo->breastsize;
$haircolor = $performerinfo->haircolor;
$hairlength = $performerinfo->hairlength;
$eyecolor = $performerinfo->eyecolor;
$ethnicity = $performerinfo->ethnicity;
$sexpref = $performerinfo->sexpref;
$pic0 = $performerinfo->picture[0];
$pic1 = $performerinfo->picture[1];
$pic2 = $performerinfo->picture[2];
$pic3 = $performerinfo->picture[3];
$pic4 = $performerinfo->picture[4];
$test = $performerinfo->picture[0];
$imgurl = 'http://www.foodtest.ru/images/big_img/sausage_3.jpg';
$imagename= basename($imgurl);
if(file_exists('./tmp/'.$imagename)){continue;}
$image = getimg($imgurl);
file_put_contents('tmp/'.$imagename,$image);
}
//baracuda reloaded
mysql_query("TRUNCATE TABLE reloaded", $dbh1);
mysql_query("TRUNCATE TABLE reloaded", $dbh2);
mysql_query("INSERT INTO reloaded SELECT * FROM ".$table."", $dbh1);
mysql_query("INSERT INTO reloaded SELECT * FROM ".$table."", $dbh2);
?>
use file_get_contents or cURL in a loop
<?php
//loop with a list of images
loop{
$imgurl = 'url to image';
$imagename= basename($imgurl);
if(file_exists('./images_folder/'.$imagename)){continue;}
$image = file_get_contents($imgurl);
file_put_contents('images_folder/'.$imagename,$image);
}
?>
or cURL
<?php
//loop this
loop{
$imgurl = 'url to image';
$imagename= basename($imgurl);
if(file_exists('./images_folder/'.$imagename)){continue;}
$image = getimg($imgurl);
file_put_contents('images_folder/'.$imagename,$image);
}
?>
<?php
//cURL function (outside of loop) to get img
function getimg($url) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'php';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
?>
in a file on your server that you want deleted put this in it and call it at END of your loops once you got all the images
<?php
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
mkdir($dir);
}
}
rrmrir('./products');
?>

Categories