Jump to content
Sign in to follow this  
yonidebest

PHP file upload

Recommended Posts

I have the following script based on the example script on http://www.w3schools.com/php/php_file_upload.asp . I get the following error now that I my host upgraded the server to PHP 5.5.The error:Strict Standards: Only variables should be passed by reference in /public_html/uploads/upload_file.php on line 7The code:

 $allowedExts = array("jpg", "jpeg", "pjpeg"); $extension = end(explode(".", $_FILES["file"]["name"])); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 3000000) && in_array($extension, $allowedExts))   {   if ($_FILES["file"]["error"] > 0)     {     echo "Return Code: " . $_FILES["file"]["error"] . "<br>";     }   else     {	 $filename = (rand() * rand());		 while (file_exists("images/" . $filename . ".jpg"))		$filename = rand() * rand();	     move_uploaded_file($_FILES["file"]["tmp_name"],     "images/" . $filename . ".jpg");	/* write desc */	$myFile = $filename . ".txt";	$fh = fopen("images/" . $myFile, 'w') or die("can't open file");		fwrite($fh, "age: " . $_POST['age'] . "rn");	fwrite($fh, "religion: " . $_POST['religion'] . "rn");	fwrite($fh, "country: " . $_POST['country'] . "rn");	fwrite($fh, "desc: " . $_POST['desc'] . "rn");	fwrite($fh, "usage: " . $_POST['usage'] . "rn");	fwrite($fh, "time/date: " . date("Y-m-d H:i:s") . "rn");	fclose($fh);     }   } else   {   echo "um, eror";   }

Can anyone tell my why I get this error and how to fix it?

 

Thanks,

Yoni

Share this post


Link to post
Share on other sites

The function end() expects a variable, not a function call.

$f = explode(".", $_FILES["file"]["name"]);$extension = end($f);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...