如果那么语句相当于PHP

时间:2013-12-16 02:02:53

标签: php ti-basic

我对php很新。但当我学会编程时,它是在TI-83计算器上。使用TI83,他们可以使用if-then语句。我正在编写一些代码来检查目录是否已经创建,如果没有创建它。我需要它以任何一种方式运行代码的后半部分。这是代码。

<?php
$dir = "/Applications/XAMPP/xamppfiles/htdocs/upload/$_POST[Itemid]/" ;
if (!file_exists($dir) and !is_dir($dir)) {
    $upload_dir = mkdir($dir, 0777);
}else{
foreach ($_FILES["file"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
    $filename = $_FILES["file"]["name"][$key];
    $filetemp = $_FILES["file"]["tmp_name"][$key];
$filetype = $_FILES["file"]["type"][$key];
$filesize = $_FILES["file"]["size"][$key];
   if (file_exists($dir . $filename))
  {
  echo $filename . " already exists. <br><br>";
  }
else
  {
  echo "Upload: " . $filename . "<br>";
  echo "Type: " . $filetype . "<br>";
  echo "Size: " . ($filesize / 1024) . " kB<br>";
  echo "Temporarily Stored in: " . $filetemp . "<br>";
  move_uploaded_file($filetemp,"$dir/$filename");
  echo "uploaded the file \"" . $filename. "\" to the \"/Applications/XAMPP/xamppfiles/htdocs/upload/\" Directory<br>" ;
  $con=mysqli_connect("localhost","root","","Inventory");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO ListPics (`1`, `Item_ItemID`)
VALUES
('$dir$filename', '$_POST[Itemid]')";


if (!mysqli_query($con,$sql))
 {
die('Error: ' . mysqli_error($con));
}
echo ($filename. " added to Database<br><br>");

mysqli_close($con);
  }
  }
  }
  }
?>

是的我知道这段代码不安全。它永远不会看到interweb(Reverently鞠躬并说“谢谢你Al Gore”)它将紧贴在VPN后面仅供个人使用。我只需要知道如何执行If If Statements

的PHP等价物

1 个答案:

答案 0 :(得分:0)

这很简单:

if(condition) {
    /* do something if condition is true */
}
else {
    /* do something else if condition is false */
}
/* do other stuff either way */

如果条件为false,如果您只想 ,那么您只需要else。如果你想以任何一种方式进行,那么根本不要使用else