I am using CodeIgniter for an iPhone app I have. The app allows for users to share images to specific individuals. It works great great, but it seems that after a certain amount of pictures to sent to an individual, posts fail to upload. I was wondering if there is something within CodeIgniter that is causing this issue and how to fix it.
here is part of our config file:
$config['proxy_ips'] = '';
$config['upload_group_path'] = "./upload/group";
$config['upload_user_path'] = "./upload/users";
$config['upload_photo_path'] = "./upload/photo";
$config['upload_video_path'] = "./upload/video";
$config['upload_weblink_path'] = "./upload/weblink";
$config['upload_drawing_path'] = "./upload/drawing";
$config['upload_text_path'] = "./upload/text";
$config['upload_movietype'] = 'mp4|flv|3gp|wmv';
$config['upload_moviesize'] = 100 * 1024; // 100M
$config['upload_alltype'] = '*';
$config['upload_allsize'] = 100 * 1024; // 100M
$config['upload_imgtype'] = 'gif|jpg|png|bmp|jpeg|jpe';
$config['upload_imgsize'] = 5 * 1024; // 5M
$config['upload_thumb_mw'] = '80';
$config['upload_thumb_mh'] = '60';
$config['upload_kmltype'] = 'kml';
$config['upload_kmlsize'] = 10 * 1024; // 10M
$config['main_category'] = array(
'user' => 'Users',
'photo' => 'Photos',
);
$config['difficulty'] = array(
'Easy' => 'Easy',
'Moderate' => 'Moderate',
'Difficult' => 'Difficult',
);
$config['max_count_per_page'] = 5;
$config['thumb_name'] = "_thumb";
$config['photo_name'] = "_photo";
And part of our api file (that draws the error 'fail to upload' in xcode's output):
$tbl_name = "posts";
$new_idx = $this->api_m->get_next_insert_idx($tbl_name);
if (isset($_FILES['datafile']) && $_FILES['datafile']['name'] != '') {
$conf = array();
$conf['upload_path'] = $this->api_m->get_upload_path($postType, $ownerID."_".$format);
$conf['allowed_types'] = $this->config->item('upload_alltype');
$conf['max_size'] = $this->config->item('upload_allsize');
$conf['overwrite'] = FALSE;
$conf['remove_spaces'] = TRUE;
if (!file_exists($conf['upload_path'])) {
mkdir($conf['upload_path']);
}
$this->upload->initialize($conf);
if ($this->upload->do_upload('datafile')) {
$fileinfo = $this->upload->data();
if ($fileinfo['file_size'] > 0) {
$postURL = base_url().substr($conf['upload_path'], 2)."/".$fileinfo['file_name'];
if ($postType == "video") {
$referenceData = base_url().substr($conf['upload_path'], 2)."/".$fileinfo['file_name'];
if (isset($_FILES['thumbfile']) && $_FILES['thumbfile']['name'] != '') {
$conf = array();
$conf['upload_path'] = $this->api_m->get_upload_path($postType, $ownerID."_".$format);
$conf['allowed_types'] = $this->config->item('upload_alltype');
$conf['max_size'] = $this->config->item('upload_allsize');
$conf['overwrite'] = FALSE;
$conf['remove_spaces'] = TRUE;
if (!file_exists($conf['upload_path'])) {
mkdir($conf['upload_path']);
}
$this->upload->initialize($conf);
if ($this->upload->do_upload('thumbfile')) {
$fileinfo = $this->upload->data();
$baseName = $this->api_m->_img_resize($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
$postURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
$baseName = $this->api_m->_img_thumb($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
$thumbURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
}
}
} else {
$baseName = $this->api_m->_img_thumb($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
$thumbURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
}
$uploadMsg = "success";
}
} else {
$uploadMsg = "fail to upload";
}
} else {
$uploadMsg = "select the post data";
}
There is no limit in Codeigniter for how many files you can upload, however are you uploading more than one file at a time so that you might reach the limit for how big files you may upload? Either in CI config or the server config.
EDIT!
Try using $this->upload->display_errors() to see what's is going wrong according to CI. My guess now is that the filename allready exists, but I'm curios to see what you get.
2nd EDIT!
In your configuration or before you load your upload class you can set the setting: max_filename_increment. When overwrite is set to FALSE, use this to set the maximum filename increment for CodeIgniter to append to the filename.
$conf['max_filename_increment'] = // What ever number you think is reasonable
Fix this and you should be good to go again :)
3rd EDIT!
I'm sorry that setting isn't available yet. So either you have to add your own upload class in your applications folder there are guides for how to add custom libraries to codeigniter else you will have to edit the Upload class in system. Note that it is not recommended to update anything in the system folder since it would be overwritten if you would update you version of CI later.
But I will of course let you know how to edit the class if you want to;
In the folder libraries in CI system you find the file Upload.php. In the latest version you find the function set_filename() on row 390. Scroll down to row 406 and you should see
for ($i = 1; $i < 100; $i++)
This is the loop that takes too few turns for your file names to be incremented. exchange 100 to a new number and try again.
for ($i = 1; $i < 1000; $i++)
That will loop ten times more than before, but I guess the limit is there for performance so check your response times before and after editing this and when uploading 3-500 files with the same name?
Regards
Related
i need to add a select with defined in admin countries to a prestashop registration form.
Any hint on how to do this?
Simple prestashop 1.7.8.2
Was searching the web, but no strict answers.
You can use additionalCustomerFormFields hook that is placed inside CustomerFormatter class.
Example usage:
https://github.com/PrestaShop/ps_emailsubscription/blob/dev/ps_emailsubscription.php#L1005
Well, i managed to sort it out myself also by:
Adding select with countries that are added to Presta in file /override/classes/form/CustomerFormatter.php
$countries = Country::getCountries((int)$this->language->id, true, false, false);
if (count($countries) > 0) {
$countryField = (new FormField)
->setName('id_country')
->setType('countrySelect')
->setLabel($this->translator->trans('Country', [], 'Shop.Forms.Labels'))
->setRequired(true);
foreach ($countries as $country) {
$countryField->addAvailableValue(
$country['id_country'],
$country['country']
);
}
$format[$countryField->getName()] = $countryField;
}
Adding to file /override/classes/AuthController.php right below:
if ($hookResult && $register_form->submit()) {
this code:
//address saving
$customer = new Customer();
$customer = $customer->getByEmail($register_form->getCustomer()->email);
$address = new Address(
null,
$this->context->language->id
);
$address->id_country = (int) Tools::getCountry();
$address->address1 = Tools::getValue('address1');
$address->postcode = Tools::getValue('postcode');
$address->city = Tools::getValue('city');
$address->phone = Tools::getValue('phone');
$address->firstname = $customer->firstname;
$address->lastname = $customer->lastname;
$address->id_customer = (int) $customer->id;
$address->id_state = 0;
$address->alias = $this->trans('My Address', [], 'Shop.Theme.Checkout');
if($address->save()){
$should_redirect = true;
} else {
$customer->delete();
$this->errors[] = $this->trans('Could not update your information, please check your data.', array(), 'Shop.Notifications.Error');
$this->redirectWithNotifications($this->getCurrentURL());
}
}
The above code is responsible to add new address within provided data. In My case additional is only country, but if You want to add more address data the fields should be added again in CustomerFormatter.php
Credits for several parts of the code:
https://prestapros.com/en/blog/additional-fields-for-registration-form-prestashop-1-7
And:
https://www.prestashop.com/forums/topic/621262-prestashop-17-add-address-in-registration-form/?do=findComment&comment=3380394
Cheers!
I need to split two different types of records in a Perl program.
Every record comes with a distinct code (ZBKPF_W and ZBUS2081_W) so they have different processing depending on that.
The information comes from parsing the file name and at the end I should get the right command based on the right parsed fields.
However, the if command in Perl apparently does not obey it and in half of the cases, I get the wrong data.
Please allow me to show the process:
2 different types of documents to process that need to be split:
# get info from filename and process each file
# BO-CC-FY-DOCID-KOFAX#.PDF
# ZBKPF_W-DE10-2020-1900000001-00034113.PDF and
# ZBUS2081_W-DE10-2019-5106000000-00034114.PDF
( $fileindex, $filetype) = split( '\.', $dir[i] );
$fname = $dir[i];
$BO = "";
$CCode = "";
$FY = "";
$DocNo = "";
$KofaxNo = "";
$CCDocNoFY = "";
$CCFYDocNo = "";
# Get the index values from filename
( $BO, $CCode, $FY, $DocNo, $KofaxNo ) = split( '\-', $fileindex );
if ( $BO == "ZBKPF_W" ) {
$R3_SAP_OBJ = "ZBKPF_W";
$CCDocNoFY = $CCode.$DocNo.$FY;
$CCFYDocNo = $CCode.$FY.$DocNo;
}
else {
if ( $BO == "ZBUS2081_W" ) {
$R3_SAP_OBJ = "ZBUS2081_W";
$CCDocNoFY = $DocNo.$FY;
$CCFYDocNo = $FY.$DocNo;
}
}
So, at the end, all the records look like ZBUS2081_W
Results:
$R3_SAP_OBJ = "ZBBUS2081_W"
$CCDocNoFY = $DocNo.$FY
$CCFYDocNo = $FY.$DocNo
always provides the else of the if command.
The correct results should be:
For ZBKPF_W-DE10-2020-1900000001-00034113.PDF
$R3_SAP_OBJ = "ZBKPF_W"
$CCDocNoFY = "DE1019000000012020"
$CCFYDocNo = "DE1020201900000001"
For ZBUS2081_W-DE10-2019-5106000000-00034114.PDF
$R3_SAP_OBJ = "ZBUS2081_W"
$CCDocNoFY = "51060000002019"
$CCFYDocNo = "20195106000000"
I have tried to use nested IF, ELSEIF and also using local variables with MY
Same results... I don't usually prefer Perl, so I far from an expert but this is a requirement for ArchiveLink, so I need it to run smoothly.
Please, if you have an idea why could be the root cause of the issue, I will appreciate that.
== compares numbers in Perl. Use eq to compare strings.
When using a string starting with Z, it's coerced to number 0, so the first condition is always true.
See perlop for more details.
I would like to ask how to add the customized line into chart by using jpgraph. For example, to identify SUNDAY on date which selecting from database, the jpgraph will draw a straight line with red color on each Sunday which will be showed on x-axis.
Does anyone meet the related issue and has been solved? Please tell me, thank you.
The code of my situation:
`
$dateLocale = new DateLocale();
$dateLocale->Set('');
$file_date = date("Ymd");
$dateArray = array();
$dataSuccessful = array(); //get from db
$dataUser_not_found = array();
$dataAcc_not_activated = array();
$dataUnsuccess_others = array();
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "example";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$dateArray[] = date("d/m/Y (D)", strtotime($row["date"]));
$dataSuccessful[] = $row["login_success_count"];
$dataUser_not_found[] = $row["unsuccess_not_found"];
$dataAcc_not_activated[] = $row["unsuccess_not_activated"];
$dataUnsuccess_others[] = $row["unsuccess_others"];
}
} else {
echo "No results in this table";
}
function strBefore($string, $substring) {
$pos = strpos($string, $substring);
if($pos === false){
return $string;
}else{
return(substr($string, 0, $pos));
}
}
function strAfter($string, $substring) {
$pos = strpos($string, $substring);
if($pos === false){
return $string;
}else{
return(substr($string, $pos+strlen($substring)));
}
}
JpgraphError::SetImageFlag(false);
JpGraphError::SetLogFile('syslog');
// Create the graph.
$graph = new Graph(2560, 1320);
//initialization of the default theme
$graph->ClearTheme();
//$graph->SetScale('datlin',0,$x_max);
$graph->SetScale('datlin');
$graph->img->SetMargin(60,150,50,60);
$graph->SetShadow();
// Create the linear plot (SUCCESSFUL)
$l1plot=new LinePlot($dataSuccessful);
$l1plot->SetColor('lightblue:0.4');
$l1plot->SetFillColor("lightblue:0.7");
$l1plot->SetWeight(2);
$l1plot->SetLegend('The total number of visit (SUCCESSFUL)');
// Create the linear plot (UNSUCCESSFUL)
$user_not_found_plot = new LinePlot($dataUser_not_found);
$user_not_found_plot->SetColor('orange:1.2');
$user_not_found_plot->SetFillColor('orange#0.2');
$user_not_found_plot->SetLegend('(UNSUCCESSFUL) User not found');
$acc_not_activated_plot = new LinePlot($dataAcc_not_activated);
$acc_not_activated_plot->SetColor('green:0.8');
$acc_not_activated_plot->SetFillColor('green#0.4');
$acc_not_activated_plot->SetLegend('(UNSUCCESSFUL) Account not activated');
$others_plot = new LinePlot($dataUnsuccess_others);
$others_plot->SetColor('lightred:1.2');
$others_plot->SetFillColor('lightred#0.4');
$others_plot->SetLegend('(UNSUCCESSFUL) Others');
$graph->title->Set('log report');
$graph->xaxis->title->Set('Last 30 days');
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->setYScale(0, 'lin', 0, 2000);
/* Add the plots to the graph */
//SUCCESSFUL numbers
$graph->Add($l1plot);
//UNSUCCESSFUL numbers
$graph->AddY(0,$user_not_found_plot);
$graph->AddY(0,$acc_not_activated_plot);
$graph->AddY(0,$others_plot);
$graph->ynaxis[0]->SetColor('red');
$graph->ynaxis[0]->title->Set('The number of visit (UNSUCCESSFUL)');
$graph->ynaxis[0]->scale->SetGrace(80);
//As demo, set the specific date on x-axis
$graph->xaxis->SetLabelFormatString('d/m/Y',true);
$graph->xaxis->setTickLabels($dateArray);
// Display the graph
// Get the handler to prevent the library from sending the image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Default is PNG so use ".png" as suffix
$fileName = "pic/oul207_log_".$file_date.".png";
$graph->img->Stream($fileName);
?>`
I guess you don't want a tick, so here's how to add a red vertical line:
require_once ('jpgraph/jpgraph_plotline.php');
$v_plot = new PlotLine();
$v_plot->SetDirection(VERTICAL);
$v_plot->SetColor('red');
$v_plot->SetPosition(2);
$graph->AddLine($v_plot);
Of course you'd need to calculate your sunday(s) relative to the x-axis and set the position(s) accordingly.
I have created category "Bag" in Magento 2. having filter attribute:
color
Size
I'm trying to get Filterable Attributes from category "Bag".
I have already done this in Magento 1.9:
Mage::app()->setCurrentStore($store);
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($categoryid);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
But it does not seem to work for 2.x
I faced the same problem recently.
I documented my investigation here.
I was not able to find framework api to provide filterable attributes for specific category, however I will share workarounds.
Basically all filterable attributes in Magento 2 can be retrived from FilterableAttributeList:
$filterableAttributes = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Layer\Category\FilterableAttributeList::class);
$attributes = $filterableAttributes->getList();
Please use DI instead of ObjectManager::getInstance(). I used it just to have more compact example :)
Retrieving filters involved in layered navigation is a bit more tricky.
$filterableAttributes = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Layer\Category\FilterableAttributeList::class);
$appState = ObjectManager::getInstance()->get(\Magento\Framework\App\State::class);
$layerResolver = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Layer\Resolver::class);
$filterList = ObjectManager::getInstance()->create(
\Magento\Catalog\Model\Layer\FilterList::class,
[
'filterableAttributes' => $filterableAttributes
]
);
$category = 1234;
$appState->setAreaCode('frontend');
$layer = $layerResolver->get();
$layer->setCurrentCategory($category);
$filters = $filterList->getFilters($layer);
However, this is not the final result. To be sure that filters are actual, it is required to check number of items for each filters. (that check is actually performed during core layered navigation rendering)
$finalFilters = [];
foreach ($filters as $filter) {
if ($filter->getItemsCount()) {
$finalFilters[] = $filter;
}
}
Then you can get filter names and values. ie:
$name = $filter->getName();
foreach ($filter->getItems() as $item) {
$value = $item->getValue();
}
Finally, I would like to add alternative solution, that is a bit brutal, thought :)
$categoryId = 1234;
$resource = ObjectManager::getInstance()->get(\Magento\Framework\App\ResourceConnection::class);
$connection = $resource->getConnection();
$select = $connection->select()->from(['ea' => $connection->getTableName('eav_attribute')], 'ea.attribute_id')
->join(['eea' => $connection->getTableName('eav_entity_attribute')], 'ea.attribute_id = eea.attribute_id')
->join(['cea' => $connection->getTableName('catalog_eav_attribute')], 'ea.attribute_id = cea.attribute_id')
->join(['cpe' => $connection->getTableName('catalog_product_entity')], 'eea.attribute_set_id = cpe.attribute_set_id')
->join(['ccp' => $connection->getTableName('catalog_category_product')], 'cpe.entity_id = ccp.product_id')
->where('cea.is_filterable = ?', 1)
->where('ccp.category_id = ?', $categoryId)
->group('ea.attribute_id');
$attributeIds = $connection->fetchCol($select);
Then it is possible to use attribute ids to load collection.
/** #var $collection \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */
$collection = $this->collectionFactory->create();
$collection->setItemObjectClass('Magento\Catalog\Model\ResourceModel\Eav\Attribute')
->addStoreLabel($this->storeManager->getStore()->getId());
$collection->addFieldToFilter('attribute_id', ['in' => $attributeIds]);
If you know how to build module then you can take help from 'FiltersProvider.php' from 'module-catalog-graph-ql\Model\Resolver\Layer'.
use Magento\Catalog\Model\Layer\Category\FilterableAttributeList as CategoryFilterableAttributeList;
use Magento\Catalog\Model\Layer\FilterListFactory;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Framework\UrlInterface;
public function __construct(
Resolver $layerResolver,
FilterListFactory $filterListFactory,
CategoryFilterableAttributeList $categoryFilterableAttributeList,
UrlInterface $urlBuilder
) {
$this->_navigation = $navigation;
$this->layerResolver = $layerResolver;
$this->filterListFactory = $filterListFactory;
$this->urlBuilder = $urlBuilder;
$this->_categoryFilterableAttributeList = $categoryFilterableAttributeList;
}
public function getCatMenu($catid)
{
$fill_arr = [];
$filterList = $this->filterListFactory->create(['filterableAttributes' => $this->_categoryFilterableAttributeList]);
$layer = clone $this->layerResolver->get();
$layer->setCurrentCategory($catid);
$filters = $filterList->getFilters($layer);
return $fill_arr;
}
Hi I am trying to find the groups out of files based on ssdeep.
I have generated ssdeep of files and kept it in csv file.
I am parsing the file in perl script as follows:
foreach( #all_lines )
{
chomp;
my $line = $_;
my #split_array = split(/,/, $line);
my $md5 = $split_array[1];
my $ssdeep = $split_array[4];
my $blk_size = (split(/:/, $ssdeep))[0];
if( $blk_size ne "")
{
my $cluster_id = check_In_Cluster($ssdeep);
print WFp "$cluster_id,$md5,$ssdeep\n";
}
}
This also checks whether the ssdeep is present in previously clustered group and if not creates new group.
Code for chec_In_Cluster
my $ssdeep = shift;
my $cmp_result;
if( $cluster_cnt > 0 ) {
$cmp_result = ssdeep_compare( $MRU_ssdeep, $ssdeep );
if( $cmp_result > 85 ) {
return $MRU_cnt;
}
}
my $d = int($cluster_cnt/4);
my $thr1 = threads->create(\&check, 0, $d, $ssdeep);
my $thr2 = threads->create(\&check, $d, 2*$d, $ssdeep);
my $thr3 = threads->create(\&check, 2*$d, 3*$d, $ssdeep);
my $thr4 = threads->create(\&check, 3*$d, $cluster_cnt, $ssdeep);
my ($ret1, $ret2, $ret3, $ret4);
$ret1 = $thr1->join();
$ret2 = $thr2->join();
$ret3 = $thr3->join();
$ret4 = $thr4->join();
if($ret1 != -1) {
$MRU_ssdeep = $ssdeep;
$MRU_cnt = $ret1;
return $MRU_cnt;
} elsif($ret2 != -1) {
$MRU_ssdeep = $ssdeep;
$MRU_cnt = $ret2;
return $MRU_cnt;
} elsif($ret3 != -1) {
$MRU_ssdeep = $ssdeep;
$MRU_cnt = $ret3;
return $MRU_cnt;
} elsif($ret4 != -1) {
$MRU_ssdeep = $ssdeep;
$MRU_cnt = $ret4;
return $MRU_cnt;
} else {
$cluster_base[$cluster_cnt] = $ssdeep;
$MRU_ssdeep = $ssdeep;
$MRU_cnt = $cluster_cnt;
$cluster_cnt++;
return $MRU_cnt;
}
and the code for chech:
sub check($$$) {
my $from = shift;
my $to = shift;
my $ssdeep = shift;
for( my $icnt = $from; $icnt < $to; $icnt++ ) {
my $cmp_result = ssdeep_compare( $cluster_base[$icnt], $ssdeep );
if( $cmp_result > 85 ) {
return $icnt;
}
}
return -1;
}
But this process takes very much time( for 20-30MB csv file it takes 8-9Hours).
I have also tried using multithreading while checking in Cluster but not much help i got from this.
Since their is no need of csv parser like Text::CSV (because of less operation on csv) i didn't used it.
can anybody please solve my issue? Is it possible to use hadoop or some other frameworks for grouping based on ssdeep?
There is a hint from Optimizing ssDeep for use at scale (2015-11-27).
Depends on your purpose, loop and match SSDEEP in different chunk size will create a N x (N-1) hash comparison. Unless you need to find partial contents, otherwise, avoid it.
It is possible to breakdown of the hash index in step 1 as suggested in the article. This is a better way for partial contents match with different chunk size.
It is possible to reduce SSDEEP hash by grouping similar hash by generate a "distance cousin" hash.