Reputation: 4423
I was running through the tutorial on http://net.tutsplus.com/tutorials/php/online-file-storage-with-php/comment-page-2/#comments and it was working fine until:
if(strlen($message) > 0)
{
$message = '<p class="error">' . $message . '</p>';
}
This line of php is found in index.php. When I few the page in firefox, it looks like the php parser stops at the greater than. Can I escape the character? Do I need to?
EDIT: All the php code:
<?php
//Load the settings
require_once("settings.php");
$message = "";
//Has the user uploaded something?
if(isset($_FILES['file']))
{
$target_path = Settings::$uploadFolder;
$target_path = $target_path . time() . '_' . basename( $_FILES['file']['name']);
//Check the password to verify legal upload
if($_POST['password'] != Settings::$password)
{
$message = "Invalid Password!";
}
else
{
//Try to move the uploaded file into the designated folder
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
$message = "The file ". basename( $_FILES['file']['name']).
" has been uploaded";
} else{
$message = "There was an error uploading the file, please try again!";
}
}
//Clear the array
unset($_FILES['file']);
}
if(strlen($message) > 0)
{
$message = '<p class="error">' . $message . '</p>';
}
?>
<html> ... </html> //my html code
Upvotes: 0
Views: 208
Reputation: 3571
What about this?
if(!empty($message)){
$message = '<p class="error">'.$message.'</p>';
}
But why don't you directly assign the paragraph tags to the error message instead of first assigning the error message to $message
and then the paragraph tags?
Upvotes: 1
Reputation: 943579
The >
won't cause the PHP parser to stop.
Without seeing the HTML output by the server, it is hard to say for sure, but since the >
is the first >
in the file it seems likely that the PHP parser never starts and the browser treats everything between the <?php
at the start of the file and the strlen($message) >
as a tag.
You need to access the PHP through a web server with PHP installed and configured to process that file (which is typically done by giving it a .php file extension).
Upvotes: 3
Reputation: 57322
there is not any error in the if condition its working fine
the possible problem in the
if(isset($_FILES['file']))
if($_POST['password'] != Settings::$password)
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path))
if you are not getting in the if body it mean the problem in
if(isset($_FILES['file']))
because if it fase than $message = "";
Upvotes: 0
Reputation: 22353
Always use Yoda Conditions and write such statements in (the) reverse(d) order (you're normally used to:
if ( 0 !== strlen( $message ) )
{
$message = 'Hello World!';
}
Anyway, you could also simply check for ! empty( $message )
Upvotes: -1