/    Sign up×
Community /Pin to ProfileBookmark

Strip Out (‘)

Hi,

I have the following code that uploads a file. If the files filename contains one or more (‘), how do I take these out before upload?

For example if the file to be upload has the following filename:

[B]david’s house.jpg[/B]

how do I change it so the uploaded file’s filename is:

[B]davids house.jpg[/B]

[CODE]<?php

if ($_FILES[“file”][“type”] == “image/jpeg”)
{
if ($_FILES[“file”][“error”] > 0)
{
echo “Return Code: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Temp file: ” . $_FILES[“file”][“tmp_name”] . “<br />”;

if (file_exists(“upload/” . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . ” Already Exists! “;
}
else
{
move_uploaded_file($_FILES[“file”][“tmp_name”],
“upload/” . $_FILES[“file”][“name”]);
$path = $_FILES[“file”][“name”];
echo “Stored in: ” . “upload/” . $path;

mysql_query(“INSERT INTO images (path)
VALUES(‘$path’)”);
}
}
}
else
{
echo “Invalid File!”;
echo $_FILES[“file”][“type”];
}
?>[/CODE]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@ploceusFeb 14.2008 — [code=php]
<?php
$string = "David's house.jpg";
$chunks = spliti("'", $string);

$new_string = null;
foreach($chunks as $part) {
$new_string .= $part;
}

var_dump($chunks);
var_dump($new_string);
?>
[/code]


Note you can have more than one ' and still works.
Copy linkTweet thisAlerts:
@YelgnidrocFeb 14.2008 — $string = str_replace("'","","David's house.jpg");
Copy linkTweet thisAlerts:
@YelgnidrocFeb 14.2008 — Or, if multiple '

do {

$s=str_replace("'","",$s); }

while(strstr("'",$s)) ;
×

Success!

Help @Dysan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...