Php code question

Hi

I have the below code that servers up house photos from another site to mine.
I know have all the photos on our own site and need to adapt this code to use them.

At present the photos are set like this

http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/house1_1.jpg
http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/house1_2.jpg
http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/house1_3.jpg
http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/house1_4.jpg

And I would now like it set like this

/media/house/photos/pics1/house1.jpg
/media/house/photos/pics1/pics2/house1.jpg
/media/house/photos/pics1/pics3/house1.jpg
/media/house/photos/pics1/pics4/house1.jpg
/media/house/photos/pics1/pics5/house1.jpg
/media/house/photos/pics1/pics6/house1.jpg
/media/house/photos/pics1/pics7/house1.jpg

so the differences are the jpg file name stays constant now but the folder location changes.
If any more information is needed please ask.

Thanks for any assistance
Cheers
Paul

function import_photos($xml, $prop_id) {
    /*
     * Function import_photos parses and loads information about photos of property to DB
     *
     * Parameters:
     * $xml: link to xml-node contents photo data
     * $prop_id: ID of property in DB;
     *
     */
    global $db_prefix, $site_root, $temp_root, $img_width, $thm_width;
	
    write_log('info',"Importing photos");
   
   //$photo = preg_replace("/[^0-9,.]/", "", $xml->Ref);
   $photo = $xml->Ref;
   
   
    $i = 1;
    while ($xml->PhotoCount >= $i){
		$url		= 'http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/'.$photo.'_'.$i.'.jpg';
		
		write_log('debug',"Importing photo: ".$url);
		
		$parts 		= pathinfo($url);
		$fname      = str_replace(' ', '_', $parts['filename']);
		$path		= $parts['dirname'].'/';
		$extension 	= '.'.$parts['extension'];
		$title		= '';
		$ip_source	= $xml->Ref;
		$order		= $i;

		// fname, type, path, remote, ordering, ip_source, title
		$values = $prop_id . ",'" . $fname . "','". $path . "','" . $order . "','" . $ip_source . "','".$title."',1,'".$extension."'";
		exec_query("INSERT INTO " . $db_prefix . "iproperty_images (propid, fname, path, ordering, ip_source, title, remote, type) VALUES (" . $values . ")");
		$i++;
	}
}

Open in new window

kennedypd1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what's your backend database? since this is a "one time" job, I suggest you do a mass Update SQL statement to update the path in your table's field instead.
kennedypd1Author Commented:
This is not a one time update.
This is for a real estate agent and they use a program in the office that uploads the photos and an xml file to the website every hour and I have a cron job that runs every hour to update the listings.
kennedypd1Author Commented:
oh and sorry this is a joomla site with mysql
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ok, so from the scripts you provided, are you saying currently it inserts the records correctly with image's URL like: http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/house1_1.jpg but now you wish to save it as ??

>>/media/house/photos/pics1/house1.jpg
>>/media/house/photos/pics1/pics2/house1.jpg

it seems that the new target folders are not standardised? can you explain on this?
kennedypd1Author Commented:
The link is provided like
path      http://www.leaderswellingtonrealestate.co.nz/hotpropertiesphotos/
fname      house1
type      .jpg

When you say folders not standardised o think I know what you mean so will try and explain.
Company uses 3rd party software inhouse so I am unable to easily change the folder structure.

xml file tells us how many photos are available for property
first photo of all properties is in folder pic1
then all other folders and pics come off the pics1 folder
so
pics1/pics2
pics1/pics3
pics1/pics4
pics1/pics5
pics1/pics6
pics1/pics7
pics1/pics8
pics1/pics9
pics1/pics10
pics1/pics11

etc and usually around 20 photos.

Does this help?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
do you have a sample of your xml file?
kennedypd1Author Commented:
Have attached xml file
really only thing related to photos is

<Ref> which is the name of the jpg images
<PhotoCount> which is the number of photos

Cheers
Listings.xml
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
sorry to keep asking questions...

if you have tags:
<Ref>LWT66511</Ref>
<PhotoCount>8</PhotoCount>

Open in new window

is that means you would like to insert 8 records into your table, with the customized paths as follows?

/media/house/photos/LWT66511/house1.jpg
/media/house/photos/LWT66511/pics2/house1.jpg
/media/house/photos/LWT66511/pics3/house1.jpg
/media/house/photos/LWT66511/pics4/house1.jpg
/media/house/photos/LWT66511/pics5/house1.jpg
/media/house/photos/LWT66511/pics6/house1.jpg
/media/house/photos/LWT66511/pics7/house1.jpg
/media/house/photos/LWT66511/pics8/house1.jpg

just want to have clarity before trying to solve it
kennedypd1Author Commented:
no $url would be

/media/house/photos/pics1/LWT66511.jpg
/media/house/photos/pics1/pics2/LWT66511.jpg
/media/house/photos/pics1/pics3/LWT66511.jpg
/media/house/photos/pics1/pics4/LWT66511.jpg
/media/house/photos/pics1/pics5/LWT66511.jpg
/media/house/photos/pics1/pics6/LWT66511.jpg
/media/house/photos/pics1/pics7/LWT66511.jpg

and then you will see from original code that it splits that $url into

$path /media/house/photos/pics1/pics8/
$fname LWT66511
$extension .jpg

hope this makes sense
Cheers
kennedypd1Author Commented:
The below works perfect apart from the first photo which is the main one

$url            = '/media/house/photos/pics1/pic'.$i.'/'.$photo.'.jpg';

Cheers
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
so a simple if statement should fixed the problem?

if ($i == 1)  {
			$url            = '/media/com_iproperty/photos/pics1/'.$photo.'.jpg';
		} else {
			$url            = '/media/com_iproperty/photos/pics1/pic'.$i.'/'.$photo.'.jpg';
		}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
do this to put the $extension, of course I think you can have this...
if ($i == 1)  {
    $url            = '/media/com_iproperty/photos/pics1/'.$photo.'.'.$extension;
 } else {
    $url            = '/media/com_iproperty/photos/pics1/pic'.$i.'/'.$photo.'.'.$extension;
 }

Open in new window

kennedypd1Author Commented:
Thank you for your help Ryan. It is working perfect
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.