Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vilbur's avatar

word 'remove' in URL causes error ?

Hi everybody, I found strange thing... I wanted recursively delete some stuff in folder structure . So I wrote route like

/products/{id}/remove/color/{color_id?}' 

which point to simple controller with function:

public function removeColor($id,$color_id=false){
    if($color_id!==false){      \File::deleteDirectory("uploads/products/$id/colors/$color_id/", true);}
    return Redirect::to('products/'.$id);
}

WHAT happens? First: It delete all stuf on FTP include the root folder, when I used it on WEB ... so it delete everything BEHIND uploads folder too... and it should not happen ;) it broke my FTP connection beacuse root was deleted... this is first strange thing..

Second: when I start think what`s going on, I realized that word 'remove' in URL causes SQL error when $color_id is not in URL. It seems that I have not some errors in my code, because, everything is working fine when word 'remove' is exchanged for 'destroy' for exaple.

So... does anybody know whats going on ? is the word 'remove' some keyword or what :) I fear to use this deleteDirectory again.

0 likes
7 replies
bashy's avatar

Able to put code in codeblocks? 3x ` or ~ at the start and end of your code?

pmall's avatar

Post your routes file.

And use three ~ to put code blocks

vilbur's avatar

... my providers tech support says ,that I deleted my root on FTP... when I ask how can I do this (I shoul not have rights to delete it), they say that they don`t know how, but it happens...

on localhost everthing works fine...

bashy's avatar

Use full paths, you can use this to get the path to the public folder

public function removeColor($id, $color_id = false)
{
    if ($color_id !== false)
    {
        \File::deleteDirectory(public_path() . 'uploads/products/' . $id . '/colors/' . $color_id . '/', true);
    }

    return Redirect::to('products/' . $id);
}
vilbur's avatar

Yeeeh, I missed that because it works on localhost. thanks! But can I ask why it delete everything on FTP when public_path() is missing? It should do not find right path and throw exception, but not delete everything everywhere ;) ... it completely clean it up , include FTP`s root folder, and it is pain, beacuse it takes hours for they to make it workin again.

Please or to participate in this conversation.