Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Strict Standards!?

Darn! I always get this error.

Code
Strict Standards: Only variables should be passed by reference in C:\XamPP\htdocs\workspace\dawnsite\test.php on line 16

This is the code.

PHP Code

<?php 
        
foreach ($b as $c) {
            
//upload multiple images
            
$d = strtolower(end(explode('.', $_FILES["file"]["name"][$c]))); //the 16th line
            
$d = $d;
            if ((
$d !== 'jpg')
             OR (
$d !== 'jpeg')
             OR (
$d !== 'gif')
             OR (
$d !== 'bmp')
             OR (
$d !== 'png')) {
                echo 
$d;
            }
        } 

$b is an array of numbers.
PHP Code

<?php 
$a 
= count($_FILES['file']['name'])-1;
$b = range(0,$a); 

I am trying to make a multiple image uploader, but it always echoes
$d no matter i use $d == 'jpg' or $d !== 'jpg'

Can someone help me? Php noob here.
BTW, here's the form.

Code
<form action="" method="post" enctype="multipart/form-data" >
<input name="file[]" type="file" multiple id="file" />
<input class="submitimg" value="Upload" type="submit" name="submitimage" />
</form>

Thanks so much. :)
there isn't a line 16..
You're trying to pass an instance by reference.
Don't do it. You need PHP 5.4 for that.
'end' just points the passed variable to the last element. If you don't create it in the memory (create a variable) it won't work.
Just change your code to
PHP Code

<?php 
$_d 
= explode('.', $_FILES["file"]["name"][$c]);
$d = strtolower(end($_d)); 
Well if you're just going to check the file extension, you could use strrchr.

PHP Code

<?php 
$d 
= strrchr(strtolower($_FILES["file"]["name"][$c]), '.'); 
(Jun 22, 2012 05:51 PM)Love2D Wrote:  Well if you're just going to check the file extension, you could use strrchr.

PHP Code

<?php 
$d 
= strrchr(strtolower($_FILES["file"]["name"][$c]), '.'); 

Just thought I would point out that there is a case-insensitive way of checking via the stristr() function. I'm not sure if you knew about it. You use strstr() (or strchr()) for case-sensitive, strchr() is just an alias of strstr().

PHP Code

<?php 
$d 
= stristr($_FILE['file']['name'][$c]), '.'); 
[Image: 8Yoto.png]
(Jun 22, 2012 10:54 PM)Phizo Wrote:  Just thought I would point out that there is a case-insensitive way of checking via the stristr() function. I'm not sure if you knew about it. You use strstr() (or strchr()) for case-sensitive, strchr() is just an alias of strstr().

PHP Code

<?php 
$d 
= stristr($_FILE['file']['name'][$c], '.'); 

While that is useful, it won't necessarily help him here. Not to mention the fact that he is looking for a specific character case, and will have to alter his if statement depending on how the user decides to name their file.
(Jun 22, 2012 11:14 PM)Love2D Wrote:  While that is useful, it won't necessarily help him here. Not to mention the fact that he is looking for a specific character case, and will have to alter his if statement depending on how the user decides to name their file.

He shouldn't be looking for a specific character case, he should make it case-insensitive. It's less work and better coding practice.
[Image: 8Yoto.png]
(Jun 22, 2012 11:18 PM)Phizo Wrote:  He shouldn't be looking for a specific character case, he should make it case-insensitive. It's less work and better coding practice.

Yeah, he should, hopefully he sees your recommendation.

Dear DAVE,

Why have you suddenly stopped putting | before and after your thread title?
(Jun 22, 2012 11:18 PM)Phizo Wrote:  He shouldn't be looking for a specific character case, he should make it case-insensitive. It's less work and better coding practice.

Let me try that. THanks. :)

(Jun 22, 2012 11:28 PM)Love2D Wrote:  Yeah, he should, hopefully he sees your recommendation.

Dear DAVE,

Why have you suddenly stopped putting | before and after your thread title?

And...I only use || for threads that needs importance in viewing. It's a rather neat way of attracting posters when I need some serious help.

And thanks for the help everyone. :)
(Jun 22, 2012 05:51 PM)Love2D Wrote:  Well if you're just going to check the file extension, you could use strrchr.

PHP Code

<?php 
$d 
= strrchr(strtolower($_FILES["file"]["name"][$c]), '.'); 

Personally I use pathinfo :
PHP Code

<?php 
$ext 
= pathinfo($file, PATHINFO_EXTENSION); 
But strrchr is also working. Except it's harder to pronounce 😏


Possibly Related Threads...
Thread / Author Replies Views Last Post
[The Brotherhood] by VinavilMar 27, 2026 09:05 AM 25 851 Mar 27, 2026 09:05 AM
Last Post: Vinavil
[Javascript]  by Nemo2478Nov 18, 2020 02:18 AM 2 89 Nov 18, 2020 02:18 AM
Last Post: vorticalbox
[PHP] by NosymbolsFeb 29, 2016 10:01 PM 3 86 Feb 29, 2016 10:01 PM
Last Post: Kedox