deleting an image

I’m trying to delete an image and I get the next error:

unlink(my.app.url/63_0.png) [<a href=‘function.unlink’>function.unlink</a>]: No such file or directory

Here is the code:

unlink(Yii::getPathOfAlias(‘webroot’).’/files/noticias/’.$model->id_noticia."_".$imagenAnterior);

The image is deleted but I still have the error.

Can anyone help me? Thanks!

You’re trying to delete the file by the URL, not ny the physical address.

Happy coding.

Are you running that code in a loop by any chance?

can you post your code for that action

The image is an optional field, if the file is not empty, I have to delete the old image and save the new one.

The old image is deleted and the new is saved but I still have the error that I posted.

Thanks for your replies!

public function actionUpdate($id)

{

&#036;model=&#036;this-&gt;loadModel(&#036;id);





// Uncomment the following line if AJAX validation is needed


//&#036;this-&gt;performAjaxValidation(&#036;model);


if(isset(&#036;_POST['Noticia']))


{


	&#036;model-&gt;attributes=&#036;_POST['Noticia'];


	


	&#036;model-&gt;archivo = CUploadedFile::getInstance(&#036;model, 'archivo');


	if(&#33;empty(&#036;model-&gt;archivo))


	{


		&#036;imagenAnterior = &#036;model-&gt;img;


		&#036;model-&gt;img = &#036;model-&gt;archivo-&gt;name;


	}


	if(&#036;model-&gt;validate()){


		if(&#036;model-&gt;save())


		{ 


			if(&#33;empty(&#036;model-&gt;archivo))


			{


				unlink(Yii::getPathOfAlias('webroot').'/files/noticias/'.&#036;model-&gt;id_noticia.&quot;_&quot;.&#036;imagenAnterior);


				&#036;model-&gt;archivo-&gt;saveAs(Yii::getPathOfAlias('webroot').'/files/noticias/'.&#036;model-&gt;id_noticia.&quot;_&quot;.&#036;model-&gt;img);


			}


			&#036;this-&gt;redirect(array('view','id'=&gt;&#036;model-&gt;id_noticia));


		}


	}


}





&#036;this-&gt;render('update',array(


	'model'=&gt;&#036;model,


));

}