Codeigniter upload multiply files with name length 32 - file

I faced an issue that in /uploads appear files with name like 69398f524b17741a34ee3f77234797e2.jpg etc. It seems that file is encoded as random MD5.
In library Upload.php I found that MD5 used for adding an number to end file name if it found that file with equal name already exist.
In model I have such code:
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1000';
$config['max_width'] = '2024';
$config['max_height'] = '2024';
$config['encrypt_name'] = TRUE;
//var_dump($config);
$this->load->library('upload', $config);
$temp_files = $_FILES;
// var_dump($temp_files);
// echo "files";
// var_dump($_FILES);
$count = count ($_FILES['userfile']['name']);
for ($i=0; $i<=$count-1; $i++){
$_FILES['file'] = array (
'name'=>$temp_files['userfile']['name'][$i],
'type'=>$temp_files['userfile']['type'][$i],
'tmp_name'=>$temp_files['userfile']['tmp_name'][$i],
'error'=>$temp_files['userfile']['error'][$i],
'size'=>$temp_files['userfile']['size'][$i]);
unset($_FILES['userfile']);
var_dump($_FILES);
if ( ! $this->upload->do_upload('file'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('insert', $error);
}
else
{
$this->upload->do_upload('file');
$tmp_data = $this->upload->data();
echo "<hr>";
var_dump($tmp_data);
}//end else
}//end for
}//end do_upload
var_dump($_FILES) return
array (size=1)
'file' =>
array (size=5)
'name' => string 'Desert.jpg' (length=10)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string 'C:\Windows\Temp\php3776.tmp' (length=27)
'error' => int 0
'size' => int 845941
var_dump($tmp_data) return
array (size=14)
'file_name' => string '69398f524b17741a34ee3f77234797e2.jpg' (length=36)
'file_type' => string 'image/jpeg' (length=10)
'file_path' => string 'D:/server/www/melok/uploads/' (length=28)
'full_path' => string 'D:/server/www/melok/uploads /69398f524b17741a34ee3f77234797e2.jpg' (length=64)
'raw_name' => string '69398f524b17741a34ee3f77234797e2' (length=32)
'orig_name' => string 'Desert.jpg' (length=10)
'client_name' => string 'Desert.jpg' (length=10)
'file_ext' => string '.jpg' (length=4)
'file_size' => float 826.11
'is_image' => boolean true
'image_width' => int 1024
'image_height' => int 768
'image_type' => string 'jpeg' (length=4)
'image_size_str' => string 'width="1024" height="768"' (length=25)

Intead of $config['encrypt_name'] = TRUE; write $config['encrypt_name'] = FALSE;

Related

Wordpress get fullurl from user_meta img

I have a user image upload (from Paid Memberships Pro Register Helper) which I want to place in a template file. If I do:
<?php
$key = 'logo';
$single = true;
$user_last = get_user_meta( $user_id, $key, $single );
if(!empty($user_last)){
var_dump($user_last); }
?>
I get:
array (size=7)
'original_filename' => string 'jp-logo.png' (length=11)
'filename' => string 'jp-logo.png' (length=11)
'fullpath' => string '/rel-local-path/jp-logo.png' (length=111)
'fullurl' => string '/full-local-path/jp-logo.png' (length=87)
'size' => int 20869
'previewpath' => string '/rel-thumbnail-path/jp-logo-200x168.png' (length=119)
'previewurl' => string 'full-thumbnail-path/jp-logo-200x168.png' (length=95)
from this, how do I echo the 'fullurl' value on the page?
Any help greatly appreciated!
Like this:
echo $user_last['fullurl'];

WooCommerce custom Loop - Attribute filters not working

I'm having some issues with some Loop for Custom Catalog Listing.
The goal: have Simple Products and some Variant Products (depend on the attribute) listed on the catalog page;
I created a custom product loop using wc_get_products with the type array('simple', 'variation') but attribute filters like size or color don't work with this listing.
This is the code:
$category = get_queried_object();
$currentCat = "";
if ( $category->slug != NULL ){
$currentCat = array($category->slug);
}
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering['orderby'] = array_shift(explode(' ', $ordering['orderby']));
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
$products_per_page = apply_filters('loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page());
$list_products = wc_get_products(array(
'meta_key' => '_price',
'status' => 'publish',
'category' => $currentCat,
'type' => array('simple', 'variation'),
'limit' => $products_per_page,
'page' => $paged,
'paginate' => true,
'return' => 'ids',
'orderby' => $ordering['orderby'],
'order' => $ordering['order'],
));
$totalProducts = (array) $list_products->products;
wc_set_loop_prop('current_page', $paged);
wc_set_loop_prop('is_paginated', wc_string_to_bool(true));
wc_set_loop_prop('page_template', get_page_template_slug());
wc_set_loop_prop('per_page', $products_per_page);
wc_set_loop_prop('total', $list_products->total);
wc_set_loop_prop('total_pages', $list_products->max_num_pages);
if($totalProducts) {
do_action('woocommerce_before_shop_loop');
woocommerce_product_loop_start();
foreach($totalProducts as $productID) {
$post_object = get_post($productID);
setup_postdata($GLOBALS['post'] =& $post_object);
wc_get_template_part('content', 'product');
}
wp_reset_postdata();
woocommerce_product_loop_end();
do_action('woocommerce_after_shop_loop');
} else {
do_action('woocommerce_no_products_found');
}
Anyone can give me an hand, so that filters start working??
Just got the way to put it to work:
1st I have a loop to get all the product ID's with a condition in the variations to confirm if a custom field (checkbox) is checked. This is mainly to get the total number of products to set up pagination.
The Goal is to include only the Variations Checked on the Catalog Page.
After, I'm doing a second loop, to get all products retrieved from the previous loop.
Here is the working solution:
if(!function_exists('wc_get_products')) {
return;
}
function get_issues($term) {
$hlterms = get_terms($term);
foreach($hlterms as $term){
// var_dump($term->taxonomy);
return true;
}
}
// Get all Attribute Filters
$outputFilters = "";
foreach($_GET as $key => $querystring){
if (strpos($key, 'filter') !== false) {
$outputFilters = array();
$newkey = str_replace("filter", "pa", $key);
if (get_issues($newkey) === true){
$outputFilters[$newkey] = $querystring;
}
}
}
// Check if in some Category
$category = get_queried_object();
$currentCat = "";
if ( $_GET['product_cat'] != NULL ){
$currentCat = $_GET['product_cat'];
} else if ($category->slug != NULL){
$currentCat = array($category->slug);
}
// 1st Loop to get total IDs
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$products_per_page = apply_filters('loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page());
$ordering['orderby'] = 'id';
$args = array(
'meta_key' => '_price',
'status' => 'publish',
'category' => $currentCat,
'type' => array('simple', 'variation'),
'limit' => 1000,
'paginate' => true,
'return' => 'ids',
);
if ($outputFilters != ""){
$args = array_merge($args, $outputFilters);
}
$list_products = wc_get_products($args);
$totalProducts = (array) $list_products->products;
$productsIDS = array();
foreach($totalProducts as $productID) {
$product_s = wc_get_product( $productID );
if ($product_s->product_type == 'simple') {
array_push($productsIDS, $productID);
} else {
if ($product_s->product_type == 'variation') {
$showCatalog = get_post_meta( $productID, '_showoncatalog', true );
if ($showCatalog == "yes"){
array_push($productsIDS, $productID);
}
}
}
}
// Final loop
$args = array(
'meta_key' => '_price',
'status' => 'publish',
'category' => $currentCat,
'type' => array('simple', 'variation'),
'limit' => $products_per_page,
'page' => $paged,
'paginate' => true,
'return' => 'ids',
'orderby' => $ordering['orderby'],
'order' => $ordering['order'],
'include' => $productsIDS,
);
if ($outputFilters != ""){
$args = array_merge($args, $outputFilters);
}
$list_products = wc_get_products($args);
$totalProducts = (array) $list_products->products;
wc_set_loop_prop('current_page', $paged);
wc_set_loop_prop('is_paginated', wc_string_to_bool(true));
wc_set_loop_prop('page_template', get_page_template_slug());
wc_set_loop_prop('per_page', $products_per_page);
wc_set_loop_prop('total', $list_products->total);
wc_set_loop_prop('total_pages', $list_products->max_num_pages);
if($totalProducts) {
do_action('woocommerce_before_shop_loop');
woocommerce_product_loop_start();
foreach($totalProducts as $productID) {
$post_object = get_post($productID);
setup_postdata($GLOBALS['post'] =& $post_object);
wc_get_template_part('content', 'product');
}
wp_reset_postdata();
woocommerce_product_loop_end();
do_action('woocommerce_after_shop_loop');
} else {
do_action('woocommerce_no_products_found');
}
/**
* Hook: woocommerce_after_shop_loop.
*
* #hooked woocommerce_pagination - 10
*/
#do_action( 'woocommerce_after_shop_loop' );
}

array to object codeigniter [REST API]

so i have an ouput data look like this
and this is my code
$var1[] = array('0' => $about_us,
'1' => $privacy,
'2' => $term_condition,
'3' => $copyright,
'4' => $faq);
$var2[] = array('0' => $voucher_redemption,
'1' => $contact_us);
$var3[] = array('0' => $about_point,
'1' => $earn_point,
'2' => $redeem_voucher);
$array["ABOUT"]=$var1;
$array["SUPPORT"]=$var2;
$array["POINT"]=$var3;
$final[]=$array;
$data["STATUS"] = "SUCCESS";
$data["MASSAGE"] = "LIST FOOTER TITLE";
$data["DATA"] = $final;
echo json_encode($data);
the problem is i want to return about [{"0":"about us"}] not only array
Make $var2 as an object, not an array
$var2= new stdClass();
$var2->0 = $voucher......
$result = array();
foreach($todo->result() as $hasil) {
$result[] = array(
'id_todo' => $hasil->id_todo,
'tanggal_input' => $hasil->tanggal_input,
'mapel' => $hasil->mapel,
'catatan' => $hasil->catatan
);
}
we can force that json_encode uses an object
json_encode($data, JSON_FORCE_OBJECT)

Cakephp - SQL not being generated for all records being inserted

I have the following code in my controller to insert records.
//Perform Inserts
$success = true;
foreach($toinsertrecords as $toinsertrecord) {
$this->BillingCenterDetail->create();
if (!$this->BillingCenterDetail->save($toinsertrecord)) {
$success = false;
echo "insert fail";
} else {echo "insert success";}
}
if ($troubleshoot) {
$log = $this->BillingCenterDetail->getDataSource()->getLog(false, false);
echo "<pre>Output from Datasource Log";
var_dump($log);
echo "</pre>";
}
The array being looped at, has the following contents (Note that the last record has the field order slightly switched, but as this is an associative array, i thought it should not matter)
array (size=3)
0 =>
array (size=1)
'BillingCenterDetail' =>
array (size=12)
'startdate' => string '2014-03-10' (length=10)
'enddate' => string '2014-03-10' (length=10)
'billing_center_id' => string '50' (length=2)
'isactive' => boolean false
'addr1' => string 'melbourne' (length=9)
'addr2' => string 'melbourne' (length=9)
'addr3' => string 'melbourne' (length=9)
'city' => string 'melbourne' (length=9)
'postcode' => string '777' (length=3)
'country' => string 'aus' (length=3)
'email' => string 'a#a.com' (length=7)
'phone' => string '1234' (length=4)
1 =>
array (size=1)
'BillingCenterDetail' =>
array (size=12)
'startdate' => string '2014-03-12' (length=10)
'enddate' => string '2028-12-10' (length=10)
'billing_center_id' => string '50' (length=2)
'isactive' => boolean false
'addr1' => string 'melbourne' (length=9)
'addr2' => string 'melbourne' (length=9)
'addr3' => string 'melbourne' (length=9)
'city' => string 'melbourne' (length=9)
'postcode' => string '777' (length=3)
'country' => string 'aus' (length=3)
'email' => string 'a#a.com' (length=7)
'phone' => string '1234' (length=4)
2 =>
array (size=1)
'BillingCenterDetail' =>
array (size=12)
'billing_center_id' => string '50' (length=2)
'startdate' => string '2014-03-11' (length=10)
'enddate' => string '2014-03-11' (length=10)
'isactive' => string '1' (length=1)
'addr1' => string 'test' (length=4)
'addr2' => string 'test' (length=4)
'addr3' => string 'test' (length=4)
'city' => string 'test' (length=4)
'postcode' => string 'test' (length=4)
'country' => string 'test' (length=4)
'email' => string 'test#test' (length=9)
'phone' => string 'test' (length=4)
This is the output from my getDataSource()->getLog statement
Output from Datasource Log
array (size=3)
'log' =>
array (size=4)
0 =>
array (size=5)
'query' => string 'SELECT `BillingCenterDetail`.`id`, `BillingCenterDetail`.`startdate`, `BillingCenterDetail`.`enddate`, `BillingCenterDetail`.`billing_center_id`, `BillingCenterDetail`.`isactive`, `BillingCenterDetail`.`addr1`, `BillingCenterDetail`.`addr2`, `BillingCenterDetail`.`addr3`, `BillingCenterDetail`.`city`, `BillingCenterDetail`.`postcode`, `BillingCenterDetail`.`country`, `BillingCenterDetail`.`email`, `BillingCenterDetail`.`phone`, `BillingCenterDetail`.`created`, `BillingCenterDetail`.`modified` FROM `bm`.`bil'... (length=718)
'params' =>
array (size=0)
...
'affected' => int 1
'numRows' => int 1
'took' => float 0
1 =>
array (size=5)
'query' => string 'BEGIN' (length=5)
'params' =>
array (size=0)
...
'affected' => int 1
'numRows' => int 1
'took' => float 0
2 =>
array (size=5)
'query' => string 'INSERT INTO `bm`.`billing_center_details` (`startdate`, `enddate`, `billing_center_id`, `isactive`, `addr1`, `addr2`, `addr3`, `city`, `postcode`, `country`, `email`, `phone`, `modified`, `created`) VALUES ('2014-03-10', '2014-03-11', 50, '0', 'melbourne', 'melbourne', 'melbourne', 'melbourne', '777', 'aus', 'a#a.com', '1234', '2014-03-11 15:47:15', '2014-03-11 15:47:15')' (length=374)
'params' =>
array (size=0)
...
'affected' => int 1
'numRows' => int 1
'took' => float 0
3 =>
array (size=5)
'query' => string 'INSERT INTO `bm`.`billing_center_details` (`startdate`, `enddate`, `billing_center_id`, `isactive`, `addr1`, `addr2`, `addr3`, `city`, `postcode`, `country`, `email`, `phone`, `modified`, `created`) VALUES ('2014-03-13', '2028-12-10', 50, '0', 'melbourne', 'melbourne', 'melbourne', 'melbourne', '777', 'aus', 'a#a.com', '1234', '2014-03-11 15:47:15', '2014-03-11 15:47:15')' (length=374)
'params' =>
array (size=0)
...
'affected' => int 1
'numRows' => int 1
'took' => float 0
'count' => int 4
'time' => float 0
You can clearly see that it has only tried to insert the first 2 records, but for some reason it hasn't inserted the 3rd record. Based on the log, it also didn't generate the 3rd Insert SQL statement?
By the time it hits the 3rd loop, the "Save" function fails, this causes $success = false in the end.
Can anyone guess why this is happening?
My guess is the data in the third entry isn't passing validation.
Possibly your model has the postcode field as numeric only? In that case this data will fail:
'postcode' => string 'test' (length=4)
To debug this, I'd add this line inside your existing failure routine:
var_dump($this->BillingCenterDetail->invalidFields());

In codeigniter, how to pass array to function parameter

As title, I have a library function $this->foo->bar(). How can I pass $upload_data array to $this->foo->bar() param?
I have this in my controller
$upload_data = $this->upload->data();
//$upload_data['file_name']
$this->foo->bar($upload_data);
Then I have this in my library
public function bar($arr){
$config['source_name'] = //How can I use $arr['file_name'] in here
}
And I got this error
Message: Illegal string offset 'file_name'
var_dump($upload_data)
array (size=14)
'file_name' => string '1358459309.JPG' (length=14)
'file_type' => string 'image/jpeg' (length=10)
'file_path' => string 'C:/wamp/www/foldering/assets/img/uploaded_photos/' (length=49)
'full_path' => string 'C:/wamp/www/foldering/assets/img/uploaded_photos/1358459309.JPG' (length=63)
'raw_name' => string '1358459309' (length=10)
'orig_name' => string '1358459309.JPG' (length=14)
'client_name' => string '200X CNY1.JPG' (length=13)
'file_ext' => string '.JPG' (length=4)
'file_size' => float 30.87
'is_image' => boolean true
'image_width' => int 640
'image_height' => int 480
'image_type' => string 'jpeg' (length=4)
'image_size_str' => string 'width="640" height="480"' (length=24)
My mistake, issue comes from another function

Resources