Php code question


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

And I would now like it set like this


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

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		= ''.$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 . ")");

Open in new window

Who is Participating?

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

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: but now you wish to save it as ??


it seems that the new target folders are not standardised? can you explain on this?
kennedypd1Author Commented:
The link is provided like
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

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

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

if you have tags:

Open in new window

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


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


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
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';

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

From novice to tech pro — start learning today.