Hi there,
I am trying to export content in a zip folder from my website to another site through FTP.
The code works however, I am having difficulty renaming the images files.
I am trying to rename the image filename to 80105_nodeid_img
At the moment, the export is producing a RePlAcEsTrInG as the image file name i.e. RePlAcEsTrInG_nodeid_img.
Please could you tell me how to replace the RePlAcEsTrInG with 80105_
The code is below:
<?php $output = "#HEADER# Version : 3 EOF : '^' EOR : '~' "; $output .= '#DEFINITION# AGENT_REF^ADDRESS_1^ADDRESS_2^TOWN^POSTCODE1^POSTCODE2^FEATURE1^FEATURE2^FEATURE3^FEATURE4^FEATURE5^FEATURE6^FEATURE7^FEATURE8^FEATURE9^FEATURE10^SUMMARY^DESCRIPTION^BRANCH_ID^STATUS_ID^BEDROOMS^PRICE^PRICE_QUALIFIER^PROP_SUB_ID^CREATE_DATE^UPDATE_DATE^DISPLAY_ADDRESS^PUBLISHED_FLAG^LET_DATE_AVAILABLE^LET_BOND^LET_TYPE_ID^LET_FURN_ID^LET_RENT_FREQUENCY^TENURE_TYPE_ID^TRANS_TYPE_ID^NEW_HOME_FLAG^MEDIA_IMAGE_00^MEDIA_IMAGE_TEXT_00^MEDIA_IMAGE_01^MEDIA_IMAGE_TEXT_01^MEDIA_IMAGE_02^MEDIA_IMAGE_TEXT_02^MEDIA_IMAGE_03^MEDIA_IMAGE_TEXT_03^MEDIA_IMAGE_04^MEDIA_IMAGE_TEXT_04^MEDIA_IMAGE_05^MEDIA_IMAGE_TEXT_05^MEDIA_IMAGE_06^MEDIA_IMAGE_TEXT_06^MEDIA_IMAGE_07^MEDIA_IMAGE_TEXT_07^MEDIA_IMAGE_08^MEDIA_IMAGE_TEXT_08^MEDIA_IMAGE_09^MEDIA_IMAGE_TEXT_09^MEDIA_IMAGE_10^MEDIA_IMAGE_TEXT_10^MEDIA_IMAGE_11^MEDIA_IMAGE_TEXT_11^MEDIA_IMAGE_12^MEDIA_IMAGE_TEXT_12^MEDIA_IMAGE_13^MEDIA_IMAGE_TEXT_13^MEDIA_IMAGE_14^MEDIA_IMAGE_TEXT_14^MEDIA_IMAGE_15^MEDIA_IMAGE_TEXT_15^MEDIA_IMAGE_16^MEDIA_IMAGE_TEXT_16^MEDIA_IMAGE_17^MEDIA_IMAGE_TEXT_17^MEDIA_IMAGE_18^MEDIA_IMAGE_TEXT_18^MEDIA_IMAGE_19^MEDIA_IMAGE_TEXT_19^MEDIA_IMAGE_20^MEDIA_IMAGE_TEXT_20^MEDIA_IMAGE_60^MEDIA_IMAGE_TEXT_60^MEDIA_IMAGE_61^MEDIA_IMAGE_TEXT_61^MEDIA_FLOOR_PLAN_00^MEDIA_FLOOR_PLAN_TEXT_00^MEDIA_FLOOR_PLAN_01^MEDIA_FLOOR_PLAN_TEXT_01^MEDIA_FLOOR_PLAN_02^MEDIA_FLOOR_PLAN_TEXT_02^MEDIA_FLOOR_PLAN_03^MEDIA_FLOOR_PLAN_TEXT_03^MEDIA_DOCUMENT_00^MEDIA_DOCUMENT_TEXT_00^MEDIA_DOCUMENT_50^MEDIA_DOCUMENT_TEXT_50^MEDIA_VIRTUAL_TOUR_00^MEDIA_VIRTUAL_TOUR_TEXT_00^~ #DATA# '; $sql = "SELECT node.nid, field_housenumber_value, street ,city, postal_code, field_summary_value, body FROM node, node_revisions, location_instance, content_type_property, location WHERE node.type='property' AND node.uid!=11 AND status=1 AND node.nid=content_type_property.nid AND field_exportinblm_value='BLM' AND node.nid=node_revisions.nid AND location_instance.nid = node.nid AND location.lid=location_instance.lid AND location_instance.nid = node.nid;";// $results = db_query($sql); $numberOfRows = 0; while($row=db_fetch_object($results)) { $numberOfRows++; $postcodeWithoutSpace = str_replace(' ','',$row->postal_code); $postcodeLength=count($postcodeWithoutSpace); $postcode2 = substr($postcodeWithoutSpace, $postcodeLength-4); $postcode1 = substr($postcodeWithoutSpace,0, $postcodeLength-4); //Preformat all the strings!! $thePropertyNode = node_load($row->nid); $output .= '80105_'.$row->nid.'^'.prep($row->field_housenumber_value).'^'; $output .= prep($row->street).'^'.prep($row->city).'^'.prep($postcode1).'^'.prep($postcode2).'^'; //Just add the first 10 features $featureFields = GetFeatures($thePropertyNode); //print var_export($thePropertyNode, true); for($featureItem = 0; $featureItem <10; $featureItem++) { $output .= prep($featureFields[$featureItem]); $output .= '^'; } if(strlen($row->field_summary) > 2) $output .= prep($row->field_summary).'^'; else $output .= prep(substr($row->body,0,300)).'^'; $output .= prep($row->body).'^80105^0^'; $output .= $thePropertyNode->field_bedrooms[0]['value'].'^'.$thePropertyNode->field_rent[0]['value'].'^0^'.getPropertyTypeOf($thePropertyNode->field_property_type[0]['value']).'^'; $output .= prep(date('Y-m-d H:i:s', $thePropertyNode->created)).'^'.prep(date('Y-m-d H:i:s', $thePropertyNode->changed)).'^';//Skip created and updated date - $thePropertyNode->date $freq = strval(getFrequencyValue($thePropertyNode->field_rent_frequency[0]['value'])); $availableFrom = substr($thePropertyNode->field_available_from[0]['value'],0,10).' '.substr($thePropertyNode->field_available_from[0]['value'],11); //2012-01-05T00:00:00 $output .= prep($row->street.', '.$row->city).'^1^'.$availableFrom.'^'.$thePropertyNode->field_deposit[0]['value'].'^0^'.getFurnishedValue($thePropertyNode->field_furnishing[0]['value']).'^'.$freq.'^'./*tenuretype*/'^2^'/*NewHome*/.'^'; //Add all the images $fieldItem = 0;//$GLOBALS['base_url'] . $GLOBALS['base_path']. //print var_export($thePropertyNode->field_image,true); for(; $thePropertyNode->field_image[$fieldItem] && $thePropertyNode->field_image[$fieldItem]['filepath']!=''; $fieldItem++) {// image AND text $fileName = $GLOBALS['base_path'].$thePropertyNode->field_image[$fieldItem]['filepath']; //create the new file name //'80105_'.$nid.'_IMG_'.sprintf('%02d', $mediaImage) //prep($GLOBALS['base_url'] . //hasFileAlreadyBeenSent $output .= ssendFile($fileName,$thePropertyNode->nid,'IMG').'^'.prep($thePropertyNode->field_image[$fieldItem]['data']['description']).'^'; } //Add the rest of the images for(; $fieldItem <21; $fieldItem++) { $output .='^^'; } //Add the EPC(s) $epcImageCount=0; for($epcCount = 0;$thePropertyNode->field_epc[$epcCount] && $thePropertyNode->field_epc[$epcCount] && $thePropertyNode->field_epc[$epcCount]['filepath']!=''; $epcCount++) { if(strpos($thePropertyNode->field_epc[$epcCount]['filepath'],'.jpg')!=false || strpos($thePropertyNode->field_epc[$epcCount]['filepath'],'.gif')!=false || strpos($thePropertyNode->field_epc[$epcCount]['filepath'],'.png')!=false) { $output.= ssendFile( $GLOBALS['base_path'].$thePropertyNode->field_epc[0]['filepath'],$thePropertyNode->nid,'IMG').'^EPC';//EPC's an image } } for(; $epcImageCount <2; $epcImageCount++) $output .='^^'; //Add up to 4 floorplans $floorplanCount = 0; for(;$thePropertyNode->field_floorplan[$floorplanCount] && $thePropertyNode->field_floorplan[$floorplanCount] && $thePropertyNode->field_floorplan[$floorplanCount]['filepath']!=''; $floorplanCount++) $output.= ssendFile( $GLOBALS['base_path'].$thePropertyNode->field_epc[0]['filepath'],$thePropertyNode->nid,'FLP').'^Floor Plan '.strval($floorplanCount+1); for(; $floorplanCount <4; $floorplanCount++) $output .='^^'; //Rename files to be in format. $output .= '^^';//MEDIA_DOCUMENT_00^MEDIA_DOCUMENT_TEXT_00 if($thePropertyNode->field_epc[0] && $thePropertyNode->field_epc[0]['filepath']!='' && strpos($thePropertyNode->field_epc[0]['filepath'],'.pdf')!=false) $output .= ssendFile( $GLOBALS['base_path'].$thePropertyNode->field_epc[0]['filepath'],$thePropertyNode->nid,'DOC').'^EPC^'; else $output .= '^^'; //MEDIA_VIRTUAL_TOUR_00^MEDIA_VIRTUAL_TOUR_TEXT_00^ $output .= '^^'; $output.='~ '; } $output .= ' #END#'; //print $output; //Save to file. Get today's date. $dateAsString = date('Ymd'); $blmFileName = 'lap'.$dateAsString.'0.BLM'; file_save_data($output, $blmFileName, FILE_EXISTS_REPLACE); mkdir("/var/www/vhosts/example.com/httpdocs/files/send/sent/"); $myFile = "/var/www/vhosts/example.com/httpdocs/files/send/sent/".$blmFileName; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $output); fclose($fh); //zip shell_exec("cd /var/www/vhosts/example.com/httpdocs/files/send/sent; zip 80105.zip *; mv 80105.zip ../;cd ..;rm -f sent/*"); //`zip x x.zip`; //$zip-> new ZipArchive(); /*$zipfileName = '/var/www/vhosts/example.com/httpdocs/files/send/80105.zip' if(($zip->open($zipfileName, ZipArchive::CREATE))!==true){ die('Error: Unable to create zip file');} $dirHandle = opendir('/var/www/vhosts/example.com/httpdocs/files/send/sent'); while($fileToAdd = readdir($dirHandle)) { print 'AddFile'.$fileToAdd; $zip->AddFile($fileToAdd); } $zip->close(); //send the zipped file