Friday, December 9, 2011

search file with folder path from folder

$directory = "C:/Documents and Settings/capacity/Desktop/Images";
$fileSPLObjects = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory),
RecursiveIteratorIterator::CHILD_FIRST
);
try {
foreach( $fileSPLObjects as $fullFileName => $fileSPLObject ) {
echo "
";
echo '
';

print_r($fileSPLObject);
//$_path=pathinfo($fileSPLObject->getFilename());
//dirname('c:/Temp/x')
//echo $_path['dirname'].$_path['basename'];
}
}
catch (UnexpectedValueException $e) {

printf("Dir [%s] contained a dodgy folder", $directory);
}?>

Saturday, December 3, 2011

Generate Csv Base on Excel


function curPageURL() {

require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();

//$data->read('Senator.xls');
//$data->read('Lamberts-RESELLER_PRICES.xls');


$returnarray=array();
// initialize reader object
$excel = new Spreadsheet_Excel_Reader();

// read spreadsheet data
$excel->read('Original_customer1.xls');

// iterate over spreadsheet cells and print as HTML table
$x=1;
$_count=1;
while($x<=$excel->sheets[0]['numRows']) {
//echo "\n";
$y=1;
while($y<=$excel->sheets[0]['numCols']) {
if($excel->sheets[0]['cells'][$x][$y]=='' and $y!=1):
$cell = $excel->sheets[0]['cells'][$x][$y] ;

$returnarray[$_count]=$cell;
$_count++;
else:
$cell = $excel->sheets[0]['cells'][$x][$y] ;

$returnarray[$_count]=$cell;
$_count++;

endif;
$y++;

}
//echo "\n";
$x++;
}


return $returnarray;
}
?>

$fp = fopen('completeorder2.csv', "w");
$_array= curPageURL();
//echo '
';

//print_r($_array);die;
$_heading=array_chunk($_array, 7, false);
//echo '
';

//print_r($_heading);die;
//print_r($_heading);die;
$_outercontent=count($_heading);

$_innercontent=count($_heading[0]);

//for($j=1;$j<=$_outercontent;$j++):
//for($i = $j ; ; $i++)
//{

// fwrite($fp,'"'.$_array[$i].'","'.$_array[$i+1].'","'.$_array[$i+2].'","'.$_array[$i+3].'","'.$_array[$i+4].'"');
//fwrite($fp,'"'.$_array[$i].'"');
// if($i%5==0):
// fwrite($fp, "\r\n");
// endif;


//}
foreach ($_heading as $fields) {
fputcsv($fp, $fields);
}


//endfor;
//die;
fclose($fp);
print_r('hello');
?>

Thursday, November 3, 2011

How to Upload Images outside of the Magento


define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';

umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);


Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(1);
$session = Mage::getSingleton('admin/session');
$session->setUser($userModel);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());


$product = Mage::getModel('catalog/product')
->loadByAttribute('sku','order');


$image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'lamberts-logo.jpg';

$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS .'l.jpg', array('image','thumbnail','small_image'), false, false);

try{
$product->save();

} catch(Exception $e){
echo $e->getMessage();
//handle your error
}
?>



Regards
Darshan Dodiya