Unique ID for Row of a Set in One Table
First, photo_id should be unique on the table. Ignoring sound practice however, you can still do this with a composite PRIMARY KEY

CREATE TABLE photos (
  user_id  int,
  photo_id int,
  PRIMARY KEY (user_id, photo_id)
);

INSERT INTO photos (user_id,photo_id) VALUES (1,1),(1,2);

--duplicate already exists
INSERT INTO photos (user_id,photo_id) VALUES (1,1);


Composite natural PRIMARY KEY's are not bad, however I'm not a fan of having them on multiple surrogate keys. If you're going to create an ID, may as well make it unique.