[英]error in php file upload
我已經一遍又一遍了,但我找不到為什么會出現此錯誤。 解析錯誤:語法錯誤,在第78行的/home/valerie2/public_html/elinkswap/snorris/file.php中出現意外的$ end。也許如果對此有更多的關注,也許可以找到我沒有做正確的事情的地方。 感謝您的光臨。
<?php
session_start();
include "connect.php";
if ($_POST["submit"])
{
//Coding
if($_SESSION["name"])
{
//variables
$name = $_FILES["file"]["name"];
$type = $_FILES["file"]["type"];
$size = $_FILES["file"]["size"];
$tmp_name = $_FILES["file"]["tmp_name"];
$error = $_FILES["file"]["error"];
if ($type =="image/jpeg" || $type =="image/gif")
{
if ($size >1100000 && $size <1700000)
{
if($error > 0)
{
echo "Error!!!!!!".$error;
}
else
{
if(file_exists("upload/".$name))
{
echo $name." already exists.";
}
else
{
$location ="upload/".$name;
move_uploaded_file($tmp_name,$location);
$user = $_SESSION["name"];
$sqlcode = mysql_query("INSERT INTO imageupload (id,user,location) VALUES ('','$user','$location')");
echo "<a href='$location'>Click here to view your image.</a>";
}
}
}
else
{
echo "Please check the size of your File..";
}
}
else
{
echo "Invalid file format.";
}
第78行就在?>
之前
如此多的嵌套IF位置很難遵循,但是您似乎無法關閉2個IF(如果提交且名稱不正確)
將您的代碼更改為:
<?php
session_start();
include "connect.php";
if ( $_POST[ "submit" ] ) {
if ( $_SESSION[ "name" ] ) {
$name = $_FILES[ "file" ][ "name" ];
$type = $_FILES[ "file" ][ "type" ];
$size = $_FILES[ "file" ][ "size" ];
$tmp_name = $_FILES[ "file" ][ "tmp_name" ];
$error = $_FILES[ "file" ][ "error" ];
if ( $type == "image/jpeg" || $type == "image/gif" ) {
if ( $size > 1100000 && $size < 1700000 ) {
if ( $error > 0 ) {
echo "Error!!!!!!" . $error;
} else {
if ( file_exists( "upload/" . $name ) ) {
echo $name . " already exists.";
}
}
} else {
$location = "upload/" . $name;
move_uploaded_file( $tmp_name , $location );
$user = $_SESSION[ "name" ];
$sqlcode = mysql_query( "INSERT INTO imageupload (id,user,location) VALUES ('','$user','$location')" );
echo "<a href='$location'>Click here to view your image.</a>";
}
}
} else {
echo "Please check the size of your File..";
}
} else {
echo "Invalid file format.";
}
?>
並且請使用這種做法來縮進代碼,這將是糾正這些錯誤的快速簡便的方法。
更改此:
if ($size >1100000 && $size <1700000)
{
if($error > 0)
{
echo "Error!!!!!!".$error;
}
至....
if ($size >1100000 && $size <1700000)
{
if($error > 0)
{
echo "Error!!!!!!".$error;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.