proggybilly
Programmer
I have a php script that runs when a user uploads a file, the basis of the app is that the php code passes a set of arguments to a perl script that encodes the data and stores it in a database.
I have a section that removes certain characters from the file names due to the passing of arguments/mysql not liking certain characters in the file names. So, I remove things such as _ / + -. I need to remove & as well since today somone uploaded a file with a name like ABCD&123.pdf. When the file name was stored in the database, the & and everything after it was stripped off. This just cannot happen. I need to remove the & and replace with nothing.
Here is the excerpt of code that I currently have.
I have tried adding & to my $removeThese by adding /\&/ and /&/ and /&/ and /\&/ nothing is stripping out the &.
Can some one please help?
I have a section that removes certain characters from the file names due to the passing of arguments/mysql not liking certain characters in the file names. So, I remove things such as _ / + -. I need to remove & as well since today somone uploaded a file with a name like ABCD&123.pdf. When the file name was stored in the database, the & and everything after it was stripped off. This just cannot happen. I need to remove the & and replace with nothing.
Here is the excerpt of code that I currently have.
Code:
<?php
$removeThese = array('/ /', '/-/', '/_/', '/\+/', '/\(/', '/\)/', '/\$/', '/\'/', '/\"/');
$replacements = array('','','','','','','','','');
if(isset($_FILES['upload1']))
{
if( $_FILES['upload1']['error'] == 0 )
{
$F1lz = array();
$target = preg_replace($removeThese,$replacements,"/tmp/".$_FILES['upload1']['name']);
if(move_uploaded_file($_FILES['upload1']['tmp_name'], $target))
{
$file1 = preg_replace($removeThese,$replacements,"/tmp/".$_FILES['upload1']['name']);
array_push($F1lz, $file1);
$err = "File ".$_FILES['upload1']['name']." upload successfully";
}else{
$err = "Failed to upload ".$_FILES['upload1']['name'];
}
}
}
I have tried adding & to my $removeThese by adding /\&/ and /&/ and /&/ and /\&/ nothing is stripping out the &.
Can some one please help?