In the CP, when we upload an image with a same name, craft will ask if we wanna keep both or replace. So in plugin, is there any way to do the replace?


You need to set the scenario SCENARIO_REPLACE or SCENARIO_CREATE depending what you like to do

$asset = new \craft\elements\Asset();
$asset->tempFilePath = $tmpFilePath;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.