Riparian Posted February 20, 2012 Share Posted February 20, 2012 Hi I have just discovered a problem that for months I could not identify in my error logs. The logs contain 100s of errors like the following Warning: imagesx(): supplied argument is not a valid Image resource in C:\Server\Apache........on line 43 Warning: imagesy(): supplied argument is not a valid Image resource in C:\Server\Apache.......on line 44 etc etc The error seems to stem from people uploading files e.g. file.to.upload.jpg because the createthumb functions contaings preg_match('/\.(\w+)/',$name,$system) On the other hand ........... file_to_upload is no problem Does someone have a fix for removing all extraneous joining characters Except the one before the image type identifier ? Cheers and any help is greatly appreciated. p.s. I have a hard time with regular expressions Quote Link to comment Share on other sites More sharing options...
sunfighter Posted February 20, 2012 Share Posted February 20, 2012 Does someone have a fix for removing all extraneous joining characters Except the one before the image type identifier ? This may not be the best way, but this is what came to mind: <?php function fixpic($name){ $ray = explode('.', $name); $ltag = '_'.$ray[count($ray)-1]; $rtag = '.'.$ray[count($ray)-1]; $name = implode('_', $ray); return(str_replace($ltag, $rtag, $name)); } $name = 'file.to.upload.jpg'; $new = fixpic($name); echo $new; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 20, 2012 Share Posted February 20, 2012 Does someone have a fix for removing all extraneous joining characters Except the one before the image type identifier ? It might be more productive to show the code which is causing the error. You are getting an error that the resource is not a valid image. Based upon what you have stated I think the problem is that you have copied the temp image and changed the name in the process but you are using a different value when trying to reference the image for some other purposes. So, I don't think the problem is due to how you are changing the name, but that you aren't using the new name in every place that you need to. Quote Link to comment Share on other sites More sharing options...
Riparian Posted February 21, 2012 Author Share Posted February 21, 2012 Thank you for the replies and sunfighter is on the mark. If it helps others in the future I have solved the problem by counting the periods in the name, replacing them with '' and then re-naming the $_FILES['upload']['name'] BEFORE using move_uploaded_file() e.g. //check if more that one period in the file name $needle='.'; $haystack=$_FILES['upload']['name']; $count = strlen($haystack) - strlen(str_replace(str_split($needle), '', $haystack)); if($count>1){ $string = $haystack; $finalPeriod = strrpos($string, "."); $string = str_replace(".", "", substr($string, 0, $finalPeriod )) . substr($string, $finalPeriod ); $_FILES['upload']['name']=$string; } //echo $_FILES['upload']['name']; Seems to work fine Cheers and thanks 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.