0

hello.....

i am using this function to create a folder in images folder. all uploaded images are store in newly created folder.it is working fine when run the code..it is creating images/newfoldername/uploadedimages.jpg in localhost. but in server same code is not working. it is creating images/uploadedimages.jpg and also creating null folder images/newfolder. there is nothing files in images/newfoldername/uploadedimages.jpg. where is the problem in server?

public function downloadImages() {		
		$imgUrlArray=$this->getImageUrls($urlArray);		
		$dir="images/".$this->imagesOf;
		
		@mkdir($dir,0777);
		for($i=0; $i<count($imgUrlArray); $i++) {
			$imageName = basename($imgUrlArray[$i]);
			$info = @getimagesize($imgUrlArray[$i]);
			if(trim($this->sizeLimit) != "" && $this->sizeLimit > 0) {
				if (count($info) > 0 && $info[0] >= $this->sizeLimit) {
					if(trim($imageName) != '' ) {
						copy($imgUrlArray[$i], $dir."/".$imageName);
					}
				}
			}
			else {
				if(trim($imageName) != '' ) {
					copy($imgUrlArray[$i], $dir."/".$imageName);
				}
			}
		}
	}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by muralikalpana
0

Permissions, Permissions, Permissions....
When the code is running from the Apache server the folder that you are trying to create the new directory in has to be writeable by the apache user or group. Make the group owner Apache (or your apache user group name) and chmod the directory to 775 so that it is writeable by members of the apache group.

drw-rw-r-- mydomainuser apache 4096 2010-10-10 05:59 mynewdir

0

thanks for your reply. i am using this code to know how to get google images from my site..actually the problem is i am not getting google images to array from my server.
i was run this code in my localhost. it is working fine. but not in my server. getting 403forbidden error. in this page downloadimagesfromgoogle.inc.php at getImageUrls() i checked like this

$str=$this->getHtmlCode($url);
			echo $str;

then it is redirecting to google images. but in my server getting this error.."google error forbidden"

Your client does not have permission to get URL /images?q=rings&hl=en&lr=&start=0&sa=N&gbv=1 from this server. (Client IP address: 174.36.204.204)

Please see Google's Terms of Service posted at http://www.google.com/terms_of_service.html

If you believe that you have received this response in error, please report your problem. However, please make sure to take a look at our Terms of Service (http://www.google.com/terms_of_service.html). In your email, please send us the entire code displayed below. Please also send us any information you may know about how you are performing your Google searches-- for example, "I'm using the Opera browser on Linux to do searches from home. My Internet access is through a dial-up account I have with the FooCorp ISP." or "I'm using the Konqueror browser on Linux to search from my job at myFoo.com. My machine's IP address is 10.20.30.40, but all of myFoo's web traffic goes through some kind of proxy server whose IP address is 10.11.12.13." (If you don't know any information like this, that's OK. But this kind of information can help us track down problems, so please tell us what you can.)

We will use all this information to diagnose the problem, and we'll hopefully have you back up and searching with Google again quickly!

Please note that although we read all the email we receive, we are not always able to send a personal response to each and every email. So don't despair if you don't hear back from us!

Also note that if you do not send us the entire code below, we will not be able to help you.

Best wishes,
The Google Team

    /+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/
    QpjOd1ztB6d2qRd9h82wcdpvA1XOX-QhYlAqG8oUdiEkx1IZE
    q8bqItVGQZDhpxhw2-XbfI_lpQbshqT8zDhFnDlHDQlPCmcx2
    I_PNVXmJxxvYY6dNUry26yrkdyUcxI0FV104bq_D3xYnZJ6xs
    Uv1sZ8WNA8rRHuUkjvtIl4oBLSvLZZfTVSyBmAxMU1K302KVI
    uh45jQzjyaRmE-PocY3VpuwOMuSWkNPBR5ovJCW-ggGzGxZs1
    eWPSnYS2bzYteObfFVB6OFUswXO0EJ6dL64ZGOi56wC1_eKCu
    2K5pWyl_uSpqcobO_kNlSBd0sloG6y_SHeKbHj9AfcY26TDl-
    ySUXKcDQlBzz8Cf2roOyskMmSeKNwN5RFhpjbF9aGkND9fVVO
    STejuGvLrCp8Q2wEvVlg3FFJ-G-6cRWGMlagbZc17g3hw6mzh
    dG_eC8f0uELNWyQ3-a3qAzmOYyRDfuLFORecNHzbZoFva9oAo
    _BbsNcfbFUFqAdxav92o3bcW2nnDVMH_ubYpWQOtnVgrIP8wh
    Gsl7JbtwQSgXhEkVcFRUjV2cWdO4gTT5-DA0_BPnpRyhjxjC3
    c4n68AuEYHtMTVmbK-fyMtcWLMTVXzLpeA61O81iEDcXuGDOH
    ljl8FF_kJoCS_V5D0jO2gIO1blu5UOB9zPJ2T9yQq2AwaJfvG
    w2Y3X95Os3DTD6_RSfKqv2C7qEHHUSW38FWaKBxhsjvouPSsj
    UmMPN0g==
    +/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+

.where is the problem?

Edited by muralikalpana: n/a

Attachments
<?php
/**
 * To download images of mentioned celebrity/person from google images
 * Strictly for educational/learning purpose only.
 * Please do not use it for commercial purpose as it is illigal !!
 *
 * @author Rochak Chauhan
 * @version 2.0
 * @see No need of cURL
 */
class DownloadImagesFromGoogle {
	private $sizeLimit=200;
	private $imagesOf="Lindsay";
	private $numberOfImages;	
	private $googleUrlArray=array();

	/**
	 * Function to download images from images.google
	 *
	 * @param string $imagesOf
	 * @param int $numberOfImages [OPTIONAL]
	 * @param int $sizeLimit [OPTIONAL]
	 */
	public function __construct($imagesOf, $numberOfImages=40, $sizeLimit=0) {
		$this->imagesOf=$imagesOf;
		$this->numberOfImages=$numberOfImages;
		$this->sizeLimit=$sizeLimit;				
		$this->googleUrlArray=$this->createGoogleUrl();		
	}
	
	/**
	 * Function the create a list of google image urls
	 * 
	 * @access private
	 * @return array
	 */
	private function createGoogleUrl() {
		$imagesOf = $this->imagesOf;
		$numberOfImages = $this->numberOfImages+20;
		$numberOfPages = ($numberOfImages/20)+1;
		$j=0;
		for($i=0; $i<$numberOfPages; $i++ ) {
			$returnArray[] = "http://images.google.co.in/images?q=".rawurlencode($imagesOf)."&hl=en&lr=&start=".$j."&sa=N&gbv=1";			
			$j += 20;
		}
		return $returnArray;
	}
	
	/**
	 * Function to download images from google
	 * 
	 * @access public
	 * @return void
	 */
	public function downloadImages() {		
		$imgUrlArray=$this->getImageUrls($urlArray);		
		$dir=$this->imagesOf;
		@mkdir($dir,0777);
		for($i=0; $i<count($imgUrlArray); $i++) {
			$imageName = basename($imgUrlArray[$i]);
			$info = @getimagesize($imgUrlArray[$i]);
			if(trim($this->sizeLimit) != "" && $this->sizeLimit > 0) {
				if (count($info) > 0 && $info[0] >= $this->sizeLimit) {
					if(trim($imageName) != '' ) {
						copy($imgUrlArray[$i], $dir."/".$imageName);
					}
				}
			}
			else {
				if(trim($imageName) != '' ) {
					copy($imgUrlArray[$i], $dir."/".$imageName);
				}
			}
		}
	}
	
	/**
	 * Function to return paths of all images to be downloaded
	 *
	 * @access public
	 * @return array
	 */
	public function getImageUrls() {
		$urlArray=$this->googleUrlArray;
		$returnArray=array();
		$returnArray1=array();
		$return=array();

		for ($j=0;$j<count($urlArray);$j++){
			$url=trim($urlArray[$j]);
			$str=$this->getHtmlCode($url);
			$pattern='/<img src=(.*)\<\/a>/Us';
			preg_match_all($pattern, $str, $returnArray, PREG_GREP_INVERT);
			$returnArray1=$returnArray[1];
			$count=count($returnArray1);
			for ($i=1;$i<$count;$i++) {
				$str1=trim(strip_tags($returnArray[1][$i]));
				$pos1=strrpos($str1,"http://");
				$pos2=strpos($str1," width");
				$link=trim(substr($str1,$pos1,$pos2-$pos1));
				$return[]=$link;

			}
		}
		return $return;
	}
	
	/**
	 * Function to get source code of a url
	 *
	 * @param string $url
	 * @access private
	 * @return string
	 */
	private function getHtmlCode($url){
		$returnStr="";
		$fp=fopen($url, "r");
		while (!feof($fp)) {
			$returnStr.=fgetc($fp);
		}
		fclose($fp);
		return $returnStr;
	}
}
<?php
set_time_limit(0);
ini_set("allow_url_fopen",1);

require_once('DownloadImagesFromGoogle.inc.php');
$downloadImagesFromGoogle = new DownloadImagesFromGoogle("rings", 40, 350);
$downloadImagesFromGoogle->downloadImages();
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.