Zerforax
Badges: 21
Rep:
?
#1
Report Thread starter 4 years ago
#1
Hi,

I'm getting Function eregi() is deprecated (see http://www.huthwaitetandoori.co.uk/photos.php for all the listed errors).

Now as I understand it, this is because of the upgrade to PHP5.3 where ereg and eregi functions no longer exists.

I've entered the CPanel to update but I can't decipher the coding..

I think I need to update the following:

if (eregi('\.jpg$|\.jpeg$|\.jpe$|\. png$|\.gif$|\.bmp$', $file)) {

if (eregi('\.jpg$|\.jpeg$', $img_file) == TRUE
&& (imageTypes() & IMG_JPG) == TRUE)
{
$src_img = imageCreateFromJpeg($orig_img);
} elseif (eregi('\.png$', $img_file) == TRUE
&& (imageTypes() & IMG_PNG) == TRUE)
{
$src_img = imageCreateFromPng($orig_img);
} elseif (eregi('\.gif$', $img_file) == TRUE
&& (imageTypes() & IMG_GIF) == TRUE)
{
$src_img = imageCreateFromGif($orig_img);
} else {
continue;

&& eregi($img_exts, $file))

What should I be changing this to fix the error?
I think I just need to change eregi to preg_match but don't understand where the "/ / i" are meant to go in..
0
reply
Async
Badges: 19
Rep:
?
#2
Report 4 years ago
#2
Yes use preg_match(),
However, all they're doing is checking file types I believe, and there's absolutely no need to even use Regex for that. PHP has an inbuilt function for checking file type extensions.

http://php.net/manual/en/function.pathinfo.php
http://stackoverflow.com/questions/1...tension-in-php

Here's a quick example.
Code:
$file_name = "async.png";
$valid_extensions = [".jpg", ".jpeg", ".bmp", ".png"];
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
echo in_array($file_extension, $valid_extensions);
Now wrap that inside a function that returns a boolean..
Code:
function is_valid_extension($file_name) { 
 $valid_extensions = [".jpg", ".jpeg", ".bmp", ".png"]; 
 $file_extension = pathinfo($file_name, PATHINFO_EXTENSION); 
 return in_array($file_extension , $valid_extensions);
}
So then just call it like,

Code:
$file_name = "omg.exe";
if (is_valid_extension($file_name)) {
 //Do something
} else {
 //Do something else
}
Hope that was what you were looking for
1
reply
Zerforax
Badges: 21
Rep:
?
#3
Report Thread starter 4 years ago
#3
(Original post by Async)
Yes use preg_match(),
However, all they're doing is checking file types I believe, and there's absolutely no need to even use Regex for that. PHP has an inbuilt function for checking file type extensions.

http://php.net/manual/en/function.pathinfo.php
http://stackoverflow.com/questions/1...tension-in-php

Here's a quick example.
Code:
$file_name = "async.png";
$valid_extensions = [".jpg", ".jpeg", ".bmp", ".png"];
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
echo in_array($file_extension, $valid_extensions);
Now wrap that inside a function that returns a boolean..
Code:
function is_valid_extension($file_name) { 
 $valid_extensions = [".jpg", ".jpeg", ".bmp", ".png"]; 
 $file_extension = pathinfo($file_name, PATHINFO_EXTENSION); 
 return in_array($file_extension , $valid_extensions);
}
So then just call it like,

Code:
$file_name = "omg.exe";
if (is_valid_extension($file_name)) {
 //Do something
} else {
 //Do something else
}
Hope that was what you were looking for
I'm afraid I'm a simpleton so even that basic information meant nothing to me
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Current uni students - are you thinking of dropping out of university?

Yes, I'm seriously considering dropping out (5)
29.41%
I'm not sure (0)
0%
No, I'm going to stick it out for now (5)
29.41%
I have already dropped out (1)
5.88%
I'm not a current university student (6)
35.29%

Watched Threads

View All