Simple Drag and Drop File Upload Tutorial - HTML, CSS & JavaScript

Поделиться
HTML-код
  • Опубликовано: 25 янв 2025

Комментарии • 121

  • @jamesmassa1999
    @jamesmassa1999 4 года назад +35

    Yes, Dom, we want to see a video on multiple file upload. : ) And thank you for all the great videos!

    • @shubhamkardam3240
      @shubhamkardam3240 4 года назад +3

      Yes, we want to see a video on multiple file upload. it will really help

  • @karenkharatyan1
    @karenkharatyan1 4 года назад +8

    Thanks for this really powerful, useful, and simply described (well-coded) tutorial. Your typing is perfectly correct and fast as always ))
    Thank you very much again.
    Small Tip: Watch this on 1.25x speed as the tutorial is a little bit long.

  • @jetzemeilink
    @jetzemeilink 3 года назад +4

    Thanks for the amazing tutorial! If there are folks who are used to write javscript without semicolons, you're going to run into trouble here with the eventListeners array of ['dragleave', 'dragend']. Don't forget to add the semicolon after the eventlistener above. Might save you half an hour :)

    • @dcode-software
      @dcode-software  3 года назад +2

      Yep!! Very good point, I was into JavaScript without semi colons until I ran into that exact problem

    • @skmedia1352
      @skmedia1352 Год назад

      @@dcode-software
      @dcode-software

  • @liorcastro
    @liorcastro 3 года назад +1

    Hey
    I have a problem.
    Whenever I drag a picture like you do in a minute 21:21
    It does not show me the "dataTransfer" It shows me "data : undefined". My code is written jquery and its looks fine.
    What do you think?

  • @aritradutta8636
    @aritradutta8636 2 года назад +1

    When connected with a PHP form the image selected is not getting submitted to the script after clicking on submit button.How to fix it ?

  • @larryshamala8929
    @larryshamala8929 2 года назад

    thank you for the video. how can you make the thump nail display the image its full size instead of enlarging for example if it is a passport size

  • @ahlbf7
    @ahlbf7 4 года назад

    Around 24 minutes, it was golden for me. Totally game changer. Thank you very much.

  • @birthdaycake572
    @birthdaycake572 2 года назад

    This is good but when I .center the , the element is where I want it to be but when I drag the photo, the dotted line becomes skinny and there is no thumbnail in it. I will have to mess around with this more to figure out what is going wrong

  • @emanuelaristizaballopez1724
    @emanuelaristizaballopez1724 3 года назад

    You can skip the click listener in drop zone replacing the div to a label, actually great job, it was really didactic

  • @_Greenflag_
    @_Greenflag_ 2 года назад

    Thanks a lot for the tutorial. Just a few things to notice :
    - 18:40 ['dragleave", "dragend"].forEach ... seems not to be working on modern version of Chrome. Instead of this, you can take this opportunity to refactor the code :
    Drop("change", inputFile)
    Drop("dragover")
    Drop("dragleave", undefined, false)
    Drop("dragend", undefined, false)
    Drop("drop", undefined, false)
    function Drop(type, eventTarget = dropZone, addClass = true) {
    eventTarget.addEventListener(type, e => {
    e.preventDefault()
    if (addClass) {
    dropZone.classList.add("drop-zone-over")
    } else {
    dropZone.classList.remove("drop-zone-over")
    }
    const currentFile = e.dataTransfer?.files || e.currentTarget.files
    if (currentFile.length) {
    inputFile.files = currentFile
    updateThumbnail(currentFile[0])
    }
    })
    }
    This covers all the cases you encounter in this video. Tip from another comment under this video : wrap your span and input with a label class="drop-zone" instead of a div (34:32).
    - 28:38 you can just use optional chaining : dropZone.querySelector(".drop-zone-prompt")?.remove()
    - 32:40 you can use this to have a centered, no repeated image, letting you see the whole image (contain) : thumbnailElement.style.background = `url('${reader.result}') center / contain rgb(255, 255, 255) no-repeat
    NB : yeah forgot to mention that at 21:50 it's not a bug. When you expand an object, look at the right little blue i icon. Javascript will evaluate the expression at the time you expand it, not at the time it is executed. It's normal : )

  • @clevermissfox
    @clevermissfox Год назад

    Instead of a span, you could use a label for the input so it’s semantic and also works to trigger the file upload window

  • @fpgroups
    @fpgroups 2 года назад

    That moment when you realize you have overworking!
    Fantastic tutorial ... Thank you so very much!

  • @niyaziozturk3967
    @niyaziozturk3967 3 года назад

    Just "Well done mate!", very good tutorial.

  • @nahojazz
    @nahojazz 2 года назад

    Very smart I'm not even at file drop portion of the video and I've learned 2 very useful skills: content: attr(data-label)😎 and how to attach 2 listeners at once using an array of types, that's very clever!! Awesome job 🤩

  • @jayashreemjaya3974
    @jayashreemjaya3974 Год назад

    Thank for this but i need to add multiple images as u told to add multiple in input , it is not working for multiple images

  • @BlezzBeats
    @BlezzBeats 2 года назад

    Best tutorial, of course

  • @district12th
    @district12th 2 года назад

    Hi, I copied everything, however, I am still having an error which is thumbnailElement.style.backgroundImage = 'url('${ reader.result }')'; --> the error exist on the dollar sign. could you help me? thank you.

  • @shandesilva8485
    @shandesilva8485 4 года назад +3

    Excellent tutorial, very well explained. Thank you much. more blessings.

  • @MuhammadAdnan2.0
    @MuhammadAdnan2.0 3 года назад

    Image is Bieng saved in localstorage ?

  • @brothercaleb
    @brothercaleb 4 года назад +1

    How about image resize on upload?

  • @borabafli
    @borabafli 2 года назад

    Man you're lifesaver. Thanks a lot!!!!!!

  • @blossombabalola1234
    @blossombabalola1234 3 года назад

    Hi! Nice video! Is it possible to have a video where there is an icon on the box that can delete the uploaded file?

  • @koshikkumaravel7660
    @koshikkumaravel7660 4 года назад +2

    Great video, please make a video for multiple file uploads. Thx

  • @MB-zj3er
    @MB-zj3er 3 года назад

    This was very helpful! Thank you for taking the time to make this video. 👍

  • @ntwohiu0252
    @ntwohiu0252 Год назад

    is it possible if i want to change, only for uploading excels?

  • @apophis2946
    @apophis2946 3 года назад +1

    data-label in the after content.... wow. I got errors when I tried ['dragleave', 'dragend']. Did this instead..
    const dragTypes = ["dragleave","dragend"]
    dragTypes.forEach(type => { ....

    • @ahmedatya6226
      @ahmedatya6226 3 года назад

      Very Good Thanks Too Much but why we got this error ?

    • @apophis2946
      @apophis2946 3 года назад

      @@ahmedatya6226 I'm not sure why. I can't remember.

  • @ilkerylmaz
    @ilkerylmaz 3 года назад

    Hello from Turkey...
    thanks, finally found what I was looking for.

    • @mehmetcemunal
      @mehmetcemunal 3 года назад +1

      Merhabalar. Isinize yaradi mi ? Ben de deniyorum ama biraz fazla eksigim var anlasilan.

    • @ilkerylmaz
      @ilkerylmaz 3 года назад

      @@mehmetcemunal evet işime yaradı benim. Sadece projemde kullanırken kücük resim kısmında hata çıktı ama benim icin onemli değildi o. Sizin nerede hata çıkıyor?

  • @sriramsrinivasan9741
    @sriramsrinivasan9741 4 года назад +1

    Really appreciate this video and your work man. This was really useful to me and works perfectly. Thank You

  • @edwardjoseph1759
    @edwardjoseph1759 2 года назад

    Hi!!, can you pls make one so that when the user reloads the page the image still remains

  • @dancehalllyrics1303
    @dancehalllyrics1303 4 года назад +3

    I would love to get one with multiple thumbnails and where it stores the uploads, thumbnails and all that in localStorage. Maybe set it up, so when you upload a file, a new empty file upload field appears right next to the one where you’ve just uploaded a file.

    • @senseicodes
      @senseicodes 4 года назад

      Check out this link on codepen. codepen.io/kent_iyo/pen/VwLbvmg I built it with UIKit framework. You should probably start learning more javascript so you can build custom things you'd like in your project.

    • @victorschweitz3506
      @victorschweitz3506 4 года назад +1

      ​@@senseicodes​, I've just started becoming a little bit better at Js, and I've figured out that my way to learn JS is by creating projects, googling what I don't understand and challenge myself to extend the projects by adding different functionalities to it. So that's what I'm trying to do everyday.

  • @khalidbiq6110
    @khalidbiq6110 3 года назад

    hello i have a question how can select path of folder or empty directory

  • @mmubeen73
    @mmubeen73 3 года назад

    hi I don't want base64 output I want output as binary. can you help me with that

  • @troyjenkins7189
    @troyjenkins7189 4 года назад

    Great video! really appreciate the walk through!

  • @omerhaciyev8773
    @omerhaciyev8773 2 года назад +1

    Perfect work.

  • @muhammadharis9514
    @muhammadharis9514 3 года назад

    What if we'll input multiple file? Will it preview multiple images?

  • @immanuelt7050
    @immanuelt7050 4 года назад

    Can we show the drop area only when the file dropping into the form? Otherwise normal form should show by default. is there any event to find whether file getting dropping or not? Accordingly we can change the class

  • @victorcaceres3592
    @victorcaceres3592 4 года назад

    Excellent Job, work perfectly in MVC Core

  • @imichux14
    @imichux14 2 года назад

    Thanks for your video man, it was really useful and it is what I was looking for :)

  • @paradisia4494
    @paradisia4494 3 года назад

    Hello thanks for this ttutorial. its very helpfull. but what if i'd like to fetch url from database and display it into thumbnail? thanks

  • @anaszh7063
    @anaszh7063 2 года назад

    hello how can we make it printable ty

  • @rev-comentarioscrudos2592
    @rev-comentarioscrudos2592 3 года назад

    I wanna know how to do this with multi images files with miniature

  • @kadetvb
    @kadetvb 2 года назад

    Awesome guide! Thank you, mate!

  • @tuxedious1782
    @tuxedious1782 4 года назад +1

    I don't get it. I did everything you did and i checked 3 times for missing parenthesis, semi-colons, etc but its still not working.
    The moment I drop an image, it opens in a new tab.

    • @margaritaitaj7482
      @margaritaitaj7482 4 года назад

      the same here...

    • @ian-jo9qv
      @ian-jo9qv 3 года назад +3

      That means you lack the .js codes that enable the drag and drop functionality specifically within the square. If you have the .js file, then make sure you reference it correctly e.g within your HTML file. It should work as long as the referenced path and the codes themselves are correct.

    • @tuxedious1782
      @tuxedious1782 3 года назад +1

      @@ian-jo9qv holy shit! Finally an answer! Thank you so much. But I have completely forgotten about this project. I'll have to do it over again to see where I fucked up. Then I'll try to do what you said

    • @ian-jo9qv
      @ian-jo9qv 3 года назад

      @@tuxedious1782 😄You're welcome.

  • @RickyRosario
    @RickyRosario 3 года назад

    Hi! is there any way i can do this in wordpress?

  • @codewatcher7397
    @codewatcher7397 4 года назад

    Hey great job with the drag & drop form. Nice tutorial!!

  • @MichaelShingo
    @MichaelShingo 2 года назад

    what a great tutorial

  • @timcoxj
    @timcoxj 2 года назад

    Is there a way to center the dropped image.... thanks so much for the lesson!

    • @wisatakata4101
      @wisatakata4101 2 года назад

      In the drop-zone__thumbanail class, you can add background-position: center;

  • @benimoza9746
    @benimoza9746 2 года назад

    how to insert this JavaScript into export default vue?

  • @vadimsidorov398
    @vadimsidorov398 4 года назад

    Event.preventDefault() on event drop don’t prevent jpg opening. Please help

  • @Seamus_Bolton
    @Seamus_Bolton 4 года назад +2

    This awesome, thanks dom

  • @muhammadsharif5526
    @muhammadsharif5526 4 года назад

    you got a new subscriber mate, thanks for your time

  • @wisatakata4101
    @wisatakata4101 2 года назад

    Hi. Thank you for this great video. It works like a charm.

  • @adykor3655
    @adykor3655 3 года назад

    I feel so silly asking this but how do you get the icon in there?

  • @vasantvohra629
    @vasantvohra629 3 года назад

    I put 'required' on and I'm getting following
    Error: An invalid form control with name='Picture' is not focusable.
    Can anyone help? How to make this dropzone as required field?
    with hidden input
    .drop-zone__input {
    display: none;

    • @vasantvohra629
      @vasantvohra629 3 года назад

      update - I did opacity:0 to still have the required form validation..

  • @judeleon8485
    @judeleon8485 2 года назад

    Thanks so much, for this well explained tutorial

  • @arazmammadov9276
    @arazmammadov9276 2 года назад

    How can make it in React JS?

  • @shrestha0144
    @shrestha0144 4 года назад

    thanks man , you're like my mdn tutor

  • @trulyharsh
    @trulyharsh 3 года назад

    the onload event should be attached to the listener before calling the readAsDataURL method.

  • @bimaindra5787
    @bimaindra5787 2 года назад

    awesome tutorial, thanks a lot!

  • @coreyfleig2139
    @coreyfleig2139 2 года назад

    Dom, Im just now learning Javascript. Your turorials are excellent!
    I just walked thru the drag drop image tutorial, and I'd like to know, how can I copy or clone the uploaded image to another element, a second image thats duplicate and bigger?

  • @sbmahapatra
    @sbmahapatra 3 года назад

    How to save the file into a folder?

  • @yumdiddlyum
    @yumdiddlyum 4 года назад

    Very nice video! Thanks for sharing your work!

  • @FabriciaPassosSoares
    @FabriciaPassosSoares Год назад

    Why is it not working on MAC computers. Could anyone say?

  • @rbelatamas
    @rbelatamas 3 года назад

    Nice work! Thank you!

  • @davidconnelly
    @davidconnelly 4 года назад

    Great job. Thank you!

  • @shpendpalushi5162
    @shpendpalushi5162 4 года назад

    Subscribed, what an amazing content

  • @AZZaidi
    @AZZaidi 3 года назад

    Hey can I ask what editor is being used in this video?

  • @shxrxnxx6054
    @shxrxnxx6054 4 года назад

    Thanks for the tutorial! But how can I insert the image into phpmyadmin?
    I tried adding sql query in php file, but it does'nt work.
    Could you make a tutorial about it?
    Thank you in advance!

    • @untildawn5714
      @untildawn5714 4 года назад

      you can encode and decode the file, also have to use blob in database

  • @sriramsrinivasan9741
    @sriramsrinivasan9741 4 года назад

    Good tutorial man!
    And how is vscode having more line spacing?

  • @danielamoreno3051
    @danielamoreno3051 3 года назад

    why is not working in my VS :(

  • @kalivasquezart
    @kalivasquezart 4 года назад

    a very helpful video, thank you!

  • @imdriedup
    @imdriedup 4 года назад

    Hello, Ive modified the drag and drop to accept only video formats and to display the video. The problem is that I can not change the source of the video. Could you give me some advice? stackoverflow.com/questions/63441429/changing-the-video-source-based-on-file-input-using-javascript
    Thanks

  • @tiagoborges5108
    @tiagoborges5108 4 года назад

    Of course we want and thank you very much

  • @ultrajorge
    @ultrajorge 3 года назад

    JS: 14:40

  • @CatLuckyy
    @CatLuckyy 4 года назад

    а есть русскоязычные такие видео? может кто ссылку кинет?

  • @haiwawaan
    @haiwawaan 3 года назад

    Thnaks you for tutorial..

  • @TopanAlfarisi
    @TopanAlfarisi 4 года назад +1

    yeayy nice tutorial, and i would love to know how to make it multiple upload with thumbnail..
    could u please create that tutorial also
    thanks

    • @dcode-software
      @dcode-software  4 года назад +2

      Cheers and yeah I do have plans to create a large scale document upload form!

  • @RodrigoMendoza7
    @RodrigoMendoza7 4 года назад

    Thank you so much for this video! Could you do another about the File Reader object? I'm looking forward to watching the video using the Fetch API as well 😀

  • @biel4787887471444
    @biel4787887471444 2 года назад

    love you bro

  • @adisonmasih
    @adisonmasih 4 года назад

    DOM please make tutorial on DOM

  • @paulm5133
    @paulm5133 3 года назад

    38 MIN UTES IS QUICK?

  • @web2905
    @web2905 4 года назад

    Thank you

  • @noah_edwrds
    @noah_edwrds 4 года назад

    Thank you !

  • @gillesbousquet195
    @gillesbousquet195 4 года назад

    Brilliant !

  • @localtoaster1273
    @localtoaster1273 2 года назад

    Dang bro this didnt work for me

  • @front-endanimal6359
    @front-endanimal6359 4 года назад

    nice, you know es6.

  • @mahathirmohammad8635
    @mahathirmohammad8635 3 года назад

    21:45 this bug ruined my life😭

  • @guillermopiedrabuena8144
    @guillermopiedrabuena8144 3 года назад

    you are fucking awesome

  • @bubuduong
    @bubuduong 4 года назад

    goooooooooooood thx a lot

  • @ramosandresc
    @ramosandresc 2 года назад

    👍

  • @gabyzenack
    @gabyzenack 4 года назад

    nice

  • @gio2156
    @gio2156 3 года назад

    Cool

  • @tomarrowsmith7386
    @tomarrowsmith7386 4 года назад

    Wanna be friends man?

  • @NOTHING-en2ue
    @NOTHING-en2ue Год назад

    great tutorial thanks a lot 💕

  • @karol_janeczko
    @karol_janeczko 2 года назад

    That was an amazing tutorial. Thank you!