I'm writing a file upload script and in order to use ImageMagick successfully, the filename can't have any strange characters like "&" or spaces..

I'm trying to replace those strange characters with underscores when the user uploads the file..

I understand I'l probably supposed to use preg_replace, but it there any way to only allow alphanumeric characters, periods, and "-", and replace everything else?

here's what im trying to use, but i get an error whenever i try to run the script:

$file_dir = "C:/sokkit/site/testim";
			foreach($_FILES as $file_name => $file_array) {
				if (is_uploaded_file($file_array['tmp_name'])) {



				move_uploaded_file($file_array['tmp_name'], 
					preg_replace('/[^a-z0-9_\-\.]/i', '_', 
					"$file_dir/$file_array[name]") or die ("Couldn't copy");

			}
		}
    $replace = array('a','b','c');
    $filename = str_replace("$replace", "_", "$filename");
    //Changes any a, b, or c to an underscore in the $filename string.
    

    Just modify the replace array and your variables.

      Write a Reply...