PHP - Error in function preg_match

Asked

Viewed 114 times

1

Boa Tarde Personal!

I have found it a little difficult to fix this error below in the version of PHP 7 when I submit the form using an UPLOAD script, the image is saved correctly in the folder and inserted in the database, but when the page returns to itself, it comes with the message:

1º I have the registration form_anuncio.php with the form:

if(@$_POST["enviar"]){

   if(@$_FILES["foto"]["name"] == true){
        $foto_form = $_FILES["foto"];
        include_once ("config/upload.php");
        $foto_old = upload_xy ($foto_form, $foto_form, 360, 280);
        $thumb_old = upload_xy ($foto_form, $foto_form, 140, 90);
        $nome_foto = md5(uniqid(time()));
        manipulacao_img($nome_foto, $thumb_old, $foto_old);
        $foto = $nome_foto . '.jpg';
        $thumb = $nome_foto . '_thumb.jpg';
    }
    $id_bandeira = strip_tags($_POST["bandeira"]);
    $id_categoria = strip_tags($_POST["categoria"]);

    $nome = strip_tags($_POST["nome"]);
    $email = strip_tags($_POST["email"]);
    $categoria = strip_tags($_POST["categoria"]);
    $descricao = str_replace("\r\n", "<br/>", strip_tags($_POST["descricao"]));
    $bandeira = strip_tags($_POST["bandeira"]);
    $data = date("Y-m-d");

    @mysqli_query($link,"INSERT INTO anuncios (ID_BANDEIRA, ID_CATEGORIA, nome, email, categoria, descricao, bandeira, data, foto, thumb, status) VALUES ('$id_bandeira','$id_categoria','$nome', '$email', '$categoria', '$descricao', '$bandeira', '$data', '$foto', '$thumb', 'Inativo')");

}

2º The script calls the upload.php that does the process and inside it has a require calling class.upload.php and the error is exactly on line 2249:

if(!preg_match('\.([^\.]*$)', $this->file_src_name, $extension)){

Warning: preg_match(): Delimiter must not be alphanumeric or backslash in C: xampp htdocs Dashboard Classified Applications config class.upload.php on line 2249

I would like to know what I need to get right in this regular expression, I am not managing to pack this item, I would like the help of you friends, thank you.

  • Try to delimit your regular expression with backslash, like this if(!preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension)){...

  • 1

    Thanks abfurlan, it worked out the change.

  • I’ll post as an answer.

1 answer

2

You need to delimit your regular expression with inverted bars.

Where is:

if(!preg_match('\.([^\.]*$)', $this->file_src_name, $extension)){...

Exchange for:

if(!preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension)){...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.