APuppyDog Posted March 28, 2009 Share Posted March 28, 2009 Hello, i have php 5 installed locally, and php 4 on the server where i host a site. On the server (with php 4) the code below works, but when i try the code locally on php 5, i get the following error "Fatal error: Only variables can be passed by reference in C:\Abyss Web Server\htdocs\query.php on line 304" if i take the code below out of the file query.php, everything works fine.. any idea how i can make this code compatible with both php4 and php5? Any help is appreciated, thanks in advance! //***********************CODE FOR PICTURE UPLOAD************************************ $mypath=realpath("listmycar.php"); $mypath=str_replace("listmycar.php","",$mypath); $mypath=str_replace("\\","/",$mypath); $mypath=str_replace("admin","files",$mypath); $upload_folder=$mypath."Auction_pics/"; for ($i = 1; $i < 11; $i++) { if (pdbfx("addfileX".$i)!='' && pdbfx("DELETEFILE".$i)!='1') $fileNameX[$i]=pdbfx("addfileX".$i); if (is_uploaded_file($_FILES['addfile'.$i]['tmp_name'])) { //Get the Filename and the File Type $fileName = $_FILES['addfile'.$i]['name']; $fileType = $_FILES['addfile'.$i]['type']; $fileName=strtolower($fileName); if (!str_contains(str_replace(".jpeg","",str_replace(".jpg","",str_replace(".gif","",str_replace(".png","",$fileName))),"."))) { if (str_contains($fileName,".jpg") || str_contains($fileName,".gif") || str_contains($fileName,".png")) { $fileName=str_replace(".","@",strtolower($fileName)); $fileext=split("@",$fileName); $fileext=$fileext[1]; $fileName="AUCTION-".$auction_id."-".genpasswordalpha(2)."-".genpasswordnum(16).".".$fileext; $fileNameX[$i]=$fileName; move_uploaded_file($_FILES['addfile'.$i]['tmp_name'],$upload_folder.''.$fileName); if ($_FILES['addfile'.$i]['size'] > 250000){ $size = GetImageSize($upload_folder.''.$fileName); $width = $size[0] ; if ($width>470) $width=470; createmagic($fileName,$width); } if ($_FILES['addfile'.$i]['size'] > 40000000){ $size = GetImageSize($upload_folder.''.$fileName); $width = $size[0] ; $height = $size[1] ; $newwidth=($width-($width/30)); $newheight=($height-($height/30)); createthumb('Auction_pics/'.$fileName,'Auction_pics/'.$fileName,$newwidth,$newheight); } //createthumb('Auction_pics/'.$fileName,'Auction_pics_T/'.$fileName,80,60); //createthumb('Auction_pics/'.$fileName,'Auction_pics_B/'.$fileName,200,150); //createthumb('Auction_pics/'.$fileName,'Auction_pics_B/'.$fileName,470,353); //if($i==1) { //createthumb('Auction_pics/'.$fileName,'Auction_pics_M/'.$fileName,200,150); //} } } } } //***************END OF FOR LOOP FOR 10 PICTURES********************************** Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 28, 2009 Share Posted March 28, 2009 if it's 5.2.4 this might apply Some users will notice that PHP applications malfunction when they upgrade to PHP 5.2.4 (included in Ubuntu 8.04 LTS) because realpath returns true for files that don't exist. This is due to the inclusion of the Hardened-PHP Project's Suhosin Patch in many distributions by default. This patch replaces PHPs realpath function with the BSD implementation, which ignores the last path component. The workaround is to use the file_exists function to verify that the file exists before using realpath to get its real path string. Quote Link to comment Share on other sites More sharing options...
APuppyDog Posted March 28, 2009 Author Share Posted March 28, 2009 so my first line of code should be replaced by the following? $Disfilename = realpath("listmycar.php"); if (file_exists($Disfilename)) { $mypath = $Disfilename; } sorry, i'm still learning php, i took over the code from someone else, so guidance is much appreciated! Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 28, 2009 Share Posted March 28, 2009 no...more like $filename="listmycar.php"; if(file_exists($filename)) { $mypath=realpath($filename); } Quote Link to comment Share on other sites More sharing options...
APuppyDog Posted March 28, 2009 Author Share Posted March 28, 2009 hi, i tried the above code, but it didn't seem to make a difference, i still get the same error. Line 288 - //***********************CODE FOR PICTURE UPLOAD************************************ Line 304 - if (!str_contains(str_replace(".jpeg","",str_replace(".jpg","",str_replace(".gif","",str_replace(".png","",$fileName))),"."))) Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 28, 2009 Share Posted March 28, 2009 in php 4.4+ if you're returning an array from a function you have to assign it to a variable before referencing it. Sorry I didn't notice the error the first time around. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 28, 2009 Share Posted March 28, 2009 also your code looks very out dated. <?php $fileName=".jpg"; if (strstr($fileName,".jpg") || strstr($fileName,".gif") || strstr($fileName,".png")) { echo "correct"; }else{ echo"not correct"; } ?> why you got this code here if your going to set it to nothink. <?php if (!str_contains(str_replace(".jpeg","",str_replace(".jpg","",str_replace(".gif","",str_replace(".png","",$fileName))),"."))) { ?> Quote Link to comment Share on other sites More sharing options...
APuppyDog Posted March 29, 2009 Author Share Posted March 29, 2009 hey guys, thanks for your help.. its not code that i wrote, it was written by someone else and i'm trying to get it compatible with php5 so taking it as i go along. taquito, are you saying the code you provided will not work at all? I'm not sure what you mean... redarrow, thanks for pointing out the outdated code, but again i'm trying to get this resolved for php5, so i guess there are some codes i can write better, but i still need it to be backwards compatible with php4, as the server is still on php4. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 Dont mean to be rude, but we are entering php6, no server should be using php4, there no way you as a programmer can move forward using a host at php 4 level. sorry it so true. if it was in php5 format then it probably work with php4 as well. a new host sounds good. it not good code practice to continue programming in php4 code. it nic to no but ot good programming seance to go backwards. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 29, 2009 Share Posted March 29, 2009 It will work and is good practice but the actual problem is with the reference to an array being returned from your function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.