Jump to content

divinedesigns1

Recommended Posts

hey guys, i got another small problem, im using the explode() function to get the extension of a file, but when i use the var_dump() function i only get back

string 'jpg' (length=3)
so this is my code
$ext = end(explode(".", $upload));

and the dot doesnt output when i upload the image also when using

$ext = end(explode(".", $upload));

it outputs this error

( ! ) Strict standards: Only variables should be passed by reference in C:\wamp\www\Newshyt\upload.php on line 33
but when i do it like this
$ext = explode(".", $upload);

it removed the error, was the upload code that give me the error was correct or not?

Link to comment
Share on other sites

end() takes the internal array pointer to last index and return its value and the passed parameter is passed by reference (see the manual you will see '&' before parameter.which means it is passing by reference. you cant reference which does not exist. when you use this.

$ext = end(explode(".", $upload));
explode() returns the array. you need to store it variable first to let it be passed by reference
[color=#000000]$arr=[/color][color=#000000]explode(".", $upload)[/color][color=#000000]$ext = end($arr);[/color]
hey guys, i got another small problem, im using the explode() function to get the extension of a file, but when i use the var_dump() function i only get back
as you are using end(). it will return the last element
and the dot doesnt output when i upload the image also when using
dot will not be outputed. dot use as delimeter here.http://php.net/explodehttp://php.net/end
Link to comment
Share on other sites

ok thanks birbal and i actually was reading it but didnt know why it wasnt showing or giving an error, thank for clearing that up for me

Link to comment
Share on other sites

As a sidenote, if you're trying to read the file name and extension, a better way is with pathinfo().
ok ill remember that one, but i was trying to get the extension only which i manage to do hehehehe
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...