SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strict Standards - Error

    Hello,

    I am using this code to upload a file to my server. The code works in the sense that it is uploading the file successfully, including preventing uploads with wrong extensions .... however every time I upload a file I get the following error

    Strict Standards: Only variables should be passed by reference in C:\upload.php on line 8

    Below is my code, I have marked line 8. Any ideas??? Thanks in advance

    Code PHP:
    <?php 
     
    $message = '';
    $target_path = "C:\mypathhere";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    $file = $_FILES['uploadedfile']['name'];
    $allowed_ext = array('csv','txt','rtf');
    $actualext = end(explode(".", $file)); // Line 8
     
    	if( $file > 1111111){ 
    			$message = 'File over 1111111 bytes';
    		} if ($message == NULL && !in_array($actualext, $allowed_ext)){ 
    			$message = 'File extension not allowed';
    		} if($message == NULL){
    			if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    				echo "The file ".  basename($file)." has been uploaded";
    			} else{
    				echo "There was an error uploading the file, please try again!";
    			}
    		}
    echo $message;
     ?>

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,136
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    This probably starts to fall on the technical side of PHP, but if I had to guess, the explode() function returns a reference in memory pointing to the array that it generated. By wrapping that function inside end() you are asking it to send the reference directly to another function (which is fine).

    The reason you get this error though is the fact that it is preferred to have a variable to help prevent memory leaks. If you didn't use the returned value of explode() you will have memory being set that is never utilized/cleared out (until Garbage Collection occurs).

    To get around the error, use the following:
    PHP Code:
    $extensions explode("."$file);
    $actualext end($extensions); 

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thank you very much; it works now !!!

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Better yet:
    PHP Code:
    $actualext pathinfo($file,  PATHINFO_EXTENSION); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •