PHP - Error in preg_match function

1

Good afternoon everyone!

I have encountered a little trouble getting this error down in the PHP 7 version when I submit the form using a UPLOAD script, the image is saved correctly in the folder and inserted into the database, but when the page returns to itself, comes with the message:

I have the form cadastra_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 upload.php that makes the process and inside it has a require calling class.upload.php and the error is exactly in 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 \ Applications \ Classifieds \ config \ class.upload.php   online 2249

I would like to know what I need to do in this regular expression, I can not fix this item, I would like the help of you friends, thank you.

    
asked by anonymous 05.09.2016 / 20:41

1 answer

2

You need to delimit your regular expression with backslashes.

Where is:

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

Switch By:

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