Olokoo
Olokoo

Reputation: 1144

How to get url of an image via drag and drop

I want to use php to copy an image to my server which is easy. But is there a way to get the url that I would be copying from using Jquery drag and drop so that the user can simply drop an image in a box and then submit a form.

Thanks Ian

Upvotes: 0

Views: 2584

Answers (1)

Shubham Monga
Shubham Monga

Reputation: 11

Try This

var data = $(event.dataTransfer.getData('text/html'));
var src = event.dataTransfer.getData("Text");


var img = data.attr('src'); // if link then it is showing undefined
if (!img) {      // if link then we are getting it from linked img source
  var img = data.find("img").attr('src');

Upvotes: 1

Related Questions