Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Swoopo's avatar

Solved - ORCHID - File Upload failed

Hello, I'm trying to upload an image with Orchid. This always fails with an error 500 / with the message "Validation error File upload error ". I kept to the specifications from the ORCHID documentation. https://orchid.software/en/docs/quickstart-crud/

I did the following.

<?php
// Hero.php

namespace App\Models\LandingPage;

use Illuminate\Database\Eloquent\Model;
use Orchid\Attachment\Attachable;
use Orchid\Screen\AsSource;

class Hero extends Model {
    use AsSource, Attachable;

    /**
     * @var array
     */
    protected $fillable = [
        'headline',
        'tagline',
        'content',
        'href',
        'href_text',
        'image',
    ];
}
// HeroEditScreen
<?php

namespace App\Orchid\Screens\Pages\LandingPage;

use App\Models\LandingPage\Hero;
use Illuminate\Http\Request;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Fields\Picture;
use Orchid\Screen\Fields\Quill;
use Orchid\Screen\Fields\Relation;
use Orchid\Screen\Fields\TextArea;
use Orchid\Screen\Fields\Upload;
use Orchid\Screen\Layout;
use Orchid\Screen\Actions\Button;
use Orchid\Screen\Screen;
use Orchid\Support\Facades\Alert;

class HeroEditScreen extends Screen {
    /**
     * Display header name.
     *
     * @var string
     */
    public $name = 'Create new hero item';

    /**
     * Display header description.
     *
     * @var string
     */
    public $description = 'Set settings for the hero section on the landing page';
    /**
     * @var bool
     */
    public $exists = false;

    /**
     * Query data.
     *
     * @param Hero $hero
     * @return array
     */
    public function query(Hero $hero): array {
        $this->exists = $hero->exists;

        if($this->exists){
            $this->name = 'Edit post';
        }

        $hero->load('attachment');

        return [
            'hero' => $hero
        ];
    }

    /**
     * Button commands.
     *
     * @return Link[]
     */
    public function commandBar(): array {
        return [
            Button::make('Create item')
                ->icon('pencil')
                ->method('createOrUpdate')
                ->canSee(!$this->exists),

            Button::make('Update')
                ->icon('note')
                ->method('createOrUpdate')
                ->canSee($this->exists),

            Button::make('Remove')
                ->icon('trash')
                ->method('remove')
                ->canSee($this->exists),
        ];
    }

    /**
     * Views.
     *
     * @return Layout[]
     */
    public function layout(): array {
        return [
            Layout::columns([
                Layout::rows([
                    Input::make('hero.headline')
                        ->title('Headline')
                        ->placeholder('Attractive but mysterious title')
                        ->help('Specify a short descriptive title for this hero carousel item.'),

                    Input::make('hero.tagline')
                        ->title('Tagline')
                        ->placeholder('Attractive but mysterious title')
                        ->help('Specify a short tagline.'),

                    TextArea::make('hero.content')
                        ->title('Description')
                        ->rows(3)
                        ->maxlength(200)
                        ->placeholder('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam.')
                        ->help('Brief description for this item.'),
                ]),
                Layout::rows([
                    Input::make('hero.href')
                        ->title('Link')
                        ->placeholder('www.google.com')
                        ->help('Provide a link if required.'),
                    Input::make('hero.href_text')
                        ->title('Link-Text')
                        ->placeholder('Visit Googles')
                        ->help('If a link exists, then return here to a text for the link.'),
                ]),
            ]),
            Layout::columns([
                Layout::rows([
                    Picture::make('hero.image')
                        ->targetId()
                ])
            ])
        ];
    }

    /**
     * @param Hero $hero
     *
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function createOrUpdate(Hero $hero, Request $request) {
        $hero->fill($request->get('hero'))->save();

        $hero->attachment()->syncWithoutDetaching(
            $request->input('hero.attachment', [])
        );

        Alert::info('You have successfully created an hero item.');

        return redirect()->route('platform.hero.list');
    }

    /**
     * @param Hero $hero
     * @return \Illuminate\Http\RedirectResponse
     * @throws \Exception
     */
    public function remove(Hero $hero) {
        $hero->delete()
            ? Alert::info('You have successfully deleted the hero item.')
            : Alert::warning('An error has occurred')
        ;

        return redirect()->route('platform.hero.list');
    }
}

0 likes
4 replies
tabuna's avatar

Hey @swoopo

  • Check that the user rights from which the script is executed have to write access.
  • Check that the file does not exceed the size specified in your php.ini configuration

You can also open your browser console under the network tab and try downloading the file. A more informative error response will be displayed there.

Swoopo's avatar

Hi,

The size given in my php.ini configuration is 8 MB. My file that I want to upload is under 2 MB. User rights should be correct. My project runs under Windows 10 with IIS. Maybe this is the problem?

Downloading the file via the network console does not work because I cannot upload the file and an http error 500 occurs

Swoopo's avatar
Swoopo
OP
Best Answer
Level 1

Hi,

it seems I have a problem with IIS and the permissions. Permissions are set but IIS doesn't seem to accept them. The upload works under Ubuntu.

EDIT: I fixed my problem. I have created a new temp folder and set the temp-directory in php.in on the new folder.

mohamedben82's avatar

Hi , I'm sorry i have followed the same steps everything is fine . But in frontend ( user interface ) trying to show all posts added but i can't display the image . This is the code i'm using : Controller : public function index(Request $request) {

    $posts = Post::with('attachment')->get();
    
  
    return view('blog', ['posts' => $posts]);
    
  }

From Blade : @foreach ($posts as $post)

          <div class="col-lg-6">
            <article class="d-flex flex-column">

              <div class="post-img">
                <img src="{{ asset($post->attachement) }}" alt="" class="img-fluid">
              </div>

              <h2 class="title">
                <a href="blog-details.html">{{$post->title}}</a>
              </h2>

              <div class="meta-top">
                <ul>
                  <li class="d-flex align-items-center"><i class="bi bi-person"></i> <a href="blog-details.html">John Doe</a></li>
                  <li class="d-flex align-items-center"><i class="bi bi-clock"></i> <a href="blog-details.html"><time datetime="2022-01-01">Jan 1, 2022</time></a></li>
                  <li class="d-flex align-items-center"><i class="bi bi-chat-dots"></i> <a href="blog-details.html">12 Comments</a></li>
                </ul>
              </div>

              <div class="content">
                <p>
                  Similique neque nam consequuntur ad non maxime aliquam quas. Quibusdam animi praesentium. Aliquam et laboriosam eius aut nostrum quidem aliquid dicta.
                </p>
              </div>

              <div class="read-more mt-auto align-self-end">
                <a href="blog-details.html">Read More <i class="bi bi-arrow-right"></i></a>
              </div>

            </article>
          </div><!-- End post list item -->
          @endforeach

          

Please or to participate in this conversation.