[SOLVED] upload problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

[SOLVED] upload problems

Post by shiznatix »

ok i started sayin somtin earlier in another post but i figured this will be easier for all parties. i have a file uploading thing but whenever i upload a file that has a ' character it turns it into a \ character. iv tried all of these and nothing has worked

Code: Select all

<?php
$file = ($_FILES['thefile']['name']);
$file = str_replace("'", "", $file);
$file = stripslashes($file);
?>

Code: Select all

<?php
stripslashes($_FILES['thefile']['name']);
$_FILES['thefile']['name'] = str_replace("'", "", $_FILES['thefile']['name']);
?>

Code: Select all

<?php
stripslashes($_FILES['thefile']['tmp_name']);
$_FILES['thefile']['tmp_name'] = str_replace("'", "", $_FILES['thefile']['tmp_name']);
?>
but nothing takes the \ mark out of the file name. how do i do this?
p.s im sure its clear that i have no idea what im doing when it comes to file upload handling :?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

whenever i upload a file that has a ' character it turns it into a \ character
Can you clarify that? Does a ' become a \ or a '' ?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

it becomes a ''
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

As a test what does the following output?

Code: Select all

echo $_FILES['thefile']['name'].'<br />';
echo str_replace('\\\'', '', $_FILES['thefile']['name']).'<br />';
echo stripslashes($_FILES['thefile']['name']).'<br />';
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

when you echo it the output is correct but whenever you take out echo the ' character is still ''
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Then don't echo ;)
The echo's were just a test, if you do:
$file = str_replace('\'', '', $_FILES['thefile']['name']); then $file should be ok; echo $file to test.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

<?php
str_replace('\'', '', $_FILES['thefile']['name']);
stripslashes($_FILES['thefile']['name']);
if(is_uploaded_file($_FILES['thefile']['tmp_name'])) {
move_uploaded_file($_FILES['thefile']['tmp_name'],$uploadto.'/'.$_FILES['thefile']['name'])
?>
is what im doing and its still messing up, sorry i didnt make that very clear in my last reply
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try:

Code: Select all

$_FILES['thefile']['name'] = stripslashes($_FILES['thefile']['name']);
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

wow...that worked. thanks like 100 million.
Post Reply