File Uploads in PHP and in Symfony2

If you’re looking for an example:
symfony2 file upload with related entities

The PHP way:

SQL

HTML

15 minutes later. Success.

The symfony2 way:
How to handle File Uploads with Doctrine
Multiple File Uploads with Symfony2
Syntax Error. Head Explodes. 3 days later, time wasted.

And this is why Symfony2 sucks.

Can you reuse the PHP way? Sure you can. It works for single and multiple uploads. It does not use the uploadprogress but neither does the Symfony2 way.
Adding a mime type check? About 4 lines of code.

Imho the Symfony2 developers should focus on creating a scripting language since they’re so hot about reinventing the wheel.

If you want to waste resources and increase costs when developing a project use Symfony2. Go ahead, I won’t stop you.
If you want to keep it slim and easy learn PHP or some other scripting language.
Simplicity always wins.

Example: C64 vs Amstrad/Schneider CPC 464, the CPC was superior in every aspect but the C64 was simpler to use. The C64 won.
Amiga vs Atari, Amiga -> simpler. Facebook vs Myspace. Facebook simple. Facebook also sucks but yeah you get the point.
Windows vs Linux. Windows just works aka simple therefore Windows is used on most workstations. New Macintosh vs Windows. Mac is easy and just works, easier than Windows. Mac Userbase grows. IOS vs Android. Personally I find Android is better but the IPhone also just works and is simple.

6 Replies to “File Uploads in PHP and in Symfony2”

  1. What? What you compare? Your solution is no OO no SOLID. Man just imagine you working on project of hundreds of class controllers, entities, services and thousands of diffrent action… your solution may be good for personal site not for huge projects where a lot of developers colaborate.

    1. it’s simple and it works. the point is you don’t need that many developers in the first place.
      OO is for people who are not used to think like a machine. classes are just a way to organize code. nothing more.
      the more you wrap your code in classes the slower it gets and the more memory it will use which will increase the cost of hardware by decreasing the number of apps you’re able to run or rephrasing the number of concurrent requests a server it will be to handle.
      There’s a sf2 file upload example if you were looking for one in another post.

  2. Ich habe noch nie so eine Scheiße gelesen 😀 Du hast dich garnicht mit Symfony2 auseinander gesetzt und nicht verstanden wofür das alles Überhaupt gut ist. Anscheinend bist du auch ein OOP Gegner und kennst die Vorteile von Design Patterns nicht. Ich war früher genauso also sieh es bitte nicht als Angriff auf deine Persönlichkeit. Nur befass dich mehr mit dem Thema und speziell mit der Wiederverwendbarkeit von Symfony2 Bundles.

    1. Als einzelner Entwickler mit 11 Jahren professioneller Erfahrung in PHP weis ich wovon ich rede bzw. schreibe. Richtig, ich bin ein OOP Gegner. Ich weis wie es einfacher geht, genauso wiederverwendbar, ohne den Zwang einer statischen Sprache und deren Dogmen zu haben.
      Symfony2 ist Bloatware. Ich bin inzwischen auf Go umgestiegen das komposition nutzt statt Objekte und dazu die Leistung von PHP um mehr als ein n-tausendfaches übersteigt und dabei noch weniger Resourcen nutzt. Ihr Kids von heute braucht außerdem scheinbar Nachhilfe in Sachen Umgangsformen.
      PHP ist eine Skriptsprache mit dynamischen Typen. Das sollte man nutzen. Wenn du Objektorientiert programmieren willst, nimm Java.
      OOP ist der Versuch der Industrie geregelte Normen auf viele Programmiersprachen umzusetzen.
      OOP ist ein schlechtes und veraltetes Konzept.
      Es mag im Industrieumfeld (Keyword: Enterprise) mit vielen Entwicklern als eine Lösung oder die jetzt etablierte Lösung hervorgegangen sein aber ist nicht der kontextbezogene effizienteste Weg eine wiederverwendbare Lösung zu finden.
      Auf gut Deutsch heist das, man kann mit PHP wiederverwendbare Komponenten schreiben, die keine OOP und speziell DI voraussetzen.
      Was Symfony2 bzw Symfony Labs ist Typenzwang und Objekorientierte Paradigmen auf eine Skripsprache mit dynamischen Typen zu übertragen, und dabei Schulungen anzubieten und Zertifizierung.
      Komposition ist die bessere Alternative.
      Beispiel:
      Du hast ein Auto.
      Ein Auto hat Räder, ein Gehäuse, Türen.
      Bei Komposition setzt sich der Typ Auto aus den Einzelteilen zusammen.
      Du kannst dir jedes beliebige Auto zusammenbauen.
      Bei OOP hast du eine Klasse Auto bei der du von vornherein alle Bestandteile definierst.
      Der Overhead bei OOP ist die Abstraktion und die Generisierung.
      Dafür gibts in Java Generics, in PHP must du mit Tricks wie DI arbeiten.
      OOP in PHP ist… Schwachsinn.
      Symfony2 ansich… wenn ein Framework schon die ganzen PHP Vars klont und dabei ~600k overhead erzeugt nur um diese Vars in einer Objektorientierten Weise abfragen zu können dann ist das einfach nur dumm, oder anders gesagt, ineffizient.
      Wenn du mit Symfony2 5000 gleichzeitige Requests ohne Fehler handlen kannst, mit einem 1245v2 ohne Cache wie Varnish nehm ich Symfony 2 ernst und gehe zurück zu PHP aber wahrscheinlicher ist das Ostern an Weihnachten gefeiert wird.
      Falls du studiert hast tust du mir ehrlich gesagt leid, denn du hast die falschen Methoden gelernt und du hast dich mit diesen Methoden ersetzbar gemacht.

  3. Yeah, exactly! And green is better than orange and apples are better than pears.
    You get the point?

    1. Yup, just that we’re not comparing fruit but how much time it takes to get something done and maintainability. Anyhow it’s an old post and I’d still prefer raw PHP over a framework like Symfony or especially Symfony, rather. Maintainability with raw PHP is just better, dependency hell is real with Symfony. For instance I have a project that requires PHP 5.6, no matter what I do, I just can’t get it to work under PHP7.1. Wasted time. Plain, raw PHP I’d spend some time fixing what’s incompatible and move on. With Symfony you have to track their changelog and remain up to date, while on PHP you don’t as much. Yes you do have to remain up to date but it’s common sense to remain up to date with your main programming language. While Symfony, who cares, who are they? They’re not relevant to keep my Infrastructure running.
      Now after 4 years of Go I still make use of my PHP skills every now and then, but I don’t use Symfony at all, at all.
      I’m also keeping that philosophy with Go. I try to keep using the stdlib as much as possible while avoiding frameworks if I can help it.

Leave a Reply to Tom Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.