laravel image validation sometimes works - laravel

I have a simple validation rule, to just require a photo being uploaded
yet, some images go through no problem, and some of them tell me, 'image required'.
Am I missing something in my code? what would let some get through and some not?
// getting all of the post data
$file = array('image' => Input::file('image'));
// setting up rules
rules = array('image' => 'required',);

Related

How to upload multiple images at once using cloudinary and lumen

I wrote a code in Lumen to upload multiple images at once using cloudinary, but the code doesn't work only the first image gets uploaded.
$images = $request->file('picture');
$uploaded = [];
foreach ($images as $image) {
error_log('for statement fires.');
Cloudder::upload($image, null, [
'folder' => '/dog-lovers',
'discard_original_filename' => true,
]);
$image_uploaded = Cloudder::getResult();
array_push($uploaded, $image_uploaded['url']);
}
return array('message'=>'successful', 'file_url'=>$uploaded);
In the above code, the for statement doesn't get called, because $images isn't an array i guess, so I made $images an array
$images[] = $request->file('picture');
Now the for statement fires up, but only the first selected image from postman gets uploaded
this is a screenshot from my postman just in case anyone is wondering how i'm uploading via postman
Does anyone have any idea why the other 4 images don't get uploaded and how to fix this?
This solution to this is to make the picture parameter on postman an array, like this picture[]
decided to post the solution incase anyone ran into similar problems

Laravel and Images validation

I have a little question about Laravel ...
I have a big form with which it is possible to send images.
I did a "PageStoreRequest" with my validation rules and everything works fine.
Depending on the length of the form, I would like that if an image is not valid, it is simply "deleted" (or "ignored") from the form and that the rest of the form is treated correctly ... So that the rest of the images are not to be sent again ...
I wonder if there is a method that would check a single field?
(like my Image Field)
And if it is not valid, delete it?
(knowing that the other fields must also pass to the Validator)
Thanks for your ideas :)
You can validate image field.
$request->validate([
'image' => 'mimes:jpeg,jpg,png'
]);
And then field is validated;
if ($request->hasFile('image') && $request->file('image')->isValid()) {
// Make something
}

error with upload images in Attachments using Croogo and cakephp

Hope someone can help me!
I'm trying to upload an image in Attachments and insert image in a page using croogo.
And when I upload i keep getting the same error message:
Security Error
The requested address was not found on this server.
Request blackholed due to "auth" violation.
The images are saved in the uploads folder but i cant get them to display on the page.
Just add some line of code in your controller
public function afterFilter() {
if (($this->request->isPost() || $this->request->isPut()) && empty($_POST) && empty($_FILES)) {
$this->Security->csrfCheck = false;
}
}
OR
May be you forgot to define multipart in your form.
echo $this->Form->create('Something', array( 'type' => 'file'));
Hope this help you.

Magento Backendgrid: Click on a data entry and display its data

I used this tutorial (especially Lesson 6 and 7) to create my own backend grid for Magento: http://www.pierrefay.com/magento-developper-guide-howto-tutorial-5
Everything works fine. I can create new data entries for my grid. If I click on an entry the VarienForm is displayed again but all the text fields are empty. This seems as if Magento thinks I want to edit all the text fields. But actually I want it to display the entry data first. But it only shows empty fields.
Can anyone help me out here? Thanks a lot!
There are a lot of things that could be wrong with your implementation, but it's impossible to say without seeing your code. Nevertheless, I'm going to try. That tutorial looks fine to me, but I haven't run the code so I can't be sure. I'm inclined to think you might have just missed something. Working in grids & tabs can be particularly delicate at the best of times.
It does sound to me like it's one of two things. It sounds like either
A) Your model data is not being stored in the registry. That means the problem is in this part of the code:
<?php
class Pfay_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
...
public function editAction()
{
$testId = $this->getRequest()->getParam('id');
$testModel = Mage::getModel('test/test')->load($testId);
if ($testModel->getId() || $testId == 0)
{
Mage::register('test_data', $testModel);
}
What this section of code does is 'registers' the selected model in Magento's registry. Later in the code, you'll see that it calls:
$form->setValues(Mage::registry('test_data')->getData());
to populate your form fields.
Try putting commands like these in the code above:
var_dump($testId);
die();
or
print_r($testModel);
die();
and running it again. Is $testId being set? Is $testModel being loaded? Is the if statement for the registry loading? If not, trace the problem back.
or it might also be
B) Your form is not prepopulating data because the column names are wrong.
Look where the code says:
<?php
class Pfay_Test_Block_Adminhtml_Test_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('test_form', array('legend'=>'ref information'));
$fieldset->addField('nom', 'text',
array(
'label' => 'Nom',
'class' => 'required-entry',
'required' => true,
'name' => 'nom',
)
);
You need to ensure that "nom" is in fact one of your model's attribute names. Did you change the attribute names when you created your test model and forgot to change it here? Change these values accordingly.
I hope that this helps you to solve your problem. Good luck!

The url from an image via custom field (wordpress)

Am not even sure if this can be done but...
Ive added a feed from my forums to wordpress it works great but I need it to auto add the url of the image in a custom field from the images in the post (feed) first image would be fine as its only ahve a slider
Is there any way to do this?
Details
Ok I think I did not explain this very well so made a few screen shots
This is my slider at the minute with my
This is an imported post one other feed I was using
On this image you can see the custom field (which I have to fill in after every import)
Adding the image url into the custom field
and finaly a view of the slider working
This is what am trying to do (auto) so my feed from my booru / forums / 2 other of my sites and (2 other peoples) sites make my home page on a new site
Hope this explain it alot more
This uses the external Simple Pie library built into WordPress to fetch the feed, get the image url and create a new post for each item and save the image url as a custom field.
To activate the process we have to hook into wp_cron. The code below does it daily but it would probably be better to do it weekly to prevent overlap. Some overlap will probably occur so this still needs a way to check if we have already imported the image
First we need a function to save the custom field after the post has been created. This section comes from another answer I found on WordPress Answers.
Edit:
This needs to be wrapped in a plugin to schedule the cron event and the cron event was missing the action to make it fire.
Edit:
Final version below tested and it works but the feed the OP is getting is using relative url's so the domain name needs to be added somewhere in the output code.
<?php
/*
Plugin Name: Fetch The Feed Image
Version: 0.1
Plugin URI: http://c3mdigital.com
Description: Sample plugin code to fetch feed image from rss and save it in a post
Author: Chris Olbekson
Author URI: http://c3mdigital.com
License: Unlicense For more information, please refer to <http://unlicense.org/>
*/
//Register the cron event on plugin activation and remove it on deactivation
register_activation_hook(__FILE__, 'c3m_activation_hook');
register_deactivation_hook(__FILE__, 'c3m_deactivation_hook');
add_action( 'c3m_scheduled_event', 'create_rss_feed_image_post');
function c3m_activation_hook() {
wp_schedule_event(time(), 'weekly', 'c3m_scheduled_event');
}
function c3m_deactivation_hook() {
wp_clear_scheduled_hook('c3m_scheduled_event');
}
function create_rss_feed_image_post() {
if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php'); // include the required file
$feed = fetch_feed('http://animelon.com/booru/rss/images'); // specify the source feed
}
foreach ($feed->get_items() as $item) :
// global $user_ID;
$new_post = array(
'post_title' => $item->get_title(),
'post_status' => 'published',
'post_date' => date('Y-m-d H:i:s'),
//'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
if ($enclosure = $item->get_enclosure() )
update_post_meta( $post_id, 'feed_image_url', $enclosure->get_link() );
endforeach;
}

Resources