0

I have a strange problem with testing file_exists.

When I hardcode the file name 007-PCSafety.zip file_exists works fine but when I post the filename 007-PCSafety.zip it doesn't recognise the file exists.

here's the code. I'm swapping the $p variable to test.

if($_POST){

$url = $_POST['dl'];

$filename = basename($url).PHP_EOL;

$p=$filename;
//$p="007-PCSafety.zip";

if(file_exists($p)){
	echo $p.' File already exists.<br><form method=post action="exists.php"><input type=text name=dl value=""><input type=submit></form>';
 
} else

	echo $p.' File does not exist.<br><form method=post action="exists.php"><input type=text name=dl value=""><input type=submit></form>';
}
3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by webwiz
0

<form method="post" action="exists.php"><input type="text" name="dl" value=""><input type="submit"></form> depending on the html version you are writing to, proper form is important
without the quotes $_post may not contain anything

Edited by almostbob: n/a

0

Can you do a "var_dump($url)" on line 4 and post the results.

reads string(16) "007-PCSafety.zip"

0

<form method="post" action="exists.php"><input type="text" name="dl" value=""><input type="submit"></form> depending on the html version you are writing to, proper form is important
without the quotes $_post may not contain anything

Thanks. It's returning the filename ok.

echo $p.' File already exists....';
0


Edit:
Ahah! I think I see the problem: Try removing the .PHP_EOL it looks like you are adding a line ending to the file name. Let me know if that does the trick.

Edited by Kognition: n/a

0


Edit:
Ahah! I think I see the problem: Try removing the .PHP_EOL it looks like you are adding a line ending to the file name. Let me know if that does the trick.

Many thanks!! That was it. Really appreciate that, it was doing my head in :)

0

You're quite welcome! I'm having one of those nights myself. I misplaced a period and spent half an hour trying to find it. :P

0

You're quite welcome! I'm having one of those nights myself. I misplaced a period and spent half an hour trying to find it. :P

Haha, Nothing worse than a missplaced period. Particularly if ur one of the 51% of the population. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.