在PHP编码中获取错误未定义的变量

时间:2013-09-21 05:39:52

标签: javascript php html

我在此代码中遇到以下错误:Strict Standards: Only variables should be passed by reference in C:\xampp\htdocs\uploader\upload.php on line 12 Success

其他错误还有Notice: Undefined variable: fulltarget in C:\xampp\htdocs\uploader\upload.php on line 101

Notice: Undefined variable: fulltarget in C:\xampp\htdocs\uploader\upload.php on line 101

以下是用于查看整个代码的pastebin链接:http://pastebin.com/JKegmNHC

此处代码也可用..您可以通过此处或使用pastebin链接查看相关行中的错误指示....

以下是代码:

    <?php

$submit=$_POST['sub'];
if(isset($submit))
{
$name=$_FILES['img']['name'];
$type=$_FILES['img']['type'];

$size=($_FILES['img']['size'])/1024;

$ext=end(explode('.',$name));
if (($ext == "gif")
|| ($ext == "jpeg")
|| ($ext == "jpg")
|| ($ext =="png")
&& ($size > 30))
{


############################## File Renaming ###################################################

$newname=uniqid();
//$ext=end(explode('.',$name));
$fullname=$newname.".".$ext;
$target="pics/";
$fulltarget=$target.$fullname;
if(move_uploaded_file($_FILES['img']['tmp_name'],$fulltarget))
{
echo "Success";
}
else
{
echo "Failed";
}
############################## File Renaming end ###################################################
}
else{
echo "not successful";
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="abhi.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Php Image Uploader</title>
</head>

<body>
<div id="a1">
<form name="frm" method="post" enctype="multipart/form-data">
<input type="file" name="img" /><br />

<input type="submit" name="sub" value="Store" />
</form>
</div>
<div id="a2">

<?php echo "
<html>
<head>
<title>Aviary Photo Editer</title>
<!-- Load Feather code -->
<script type='text/javascript' src='http://feather.aviary.com/js/feather.js'></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: 'ceegvx4siylhayrr',
apiVersion: 3,
theme: 'dark', // Check out our new 'light' and 'dark' themes!
tools: 'enhance,frames,crop,orientation,brightness,saturation,sharpness,draw,redeye,blemish,effects,stickers,resize,focus,contrast,warmth,colorsplash,text,whiten',
appendTo: '',
onSave: function(imageID, newURL) {
    var img = document.getElementById(imageID);
    img.src = newURL;
},
onError: function(errorObj) {
    alert(errorObj.message);
}
});
function launchEditor(id, src) {
featherEditor.launch({
    image: id,
    url: src
 });
return false;
}
 </script>
</head>

<body>

<div id='injection_site'></div>

<img id='image1' src='$fulltarget'/>

<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick=\"return launchEditor('image1', '$fulltarget');\" /></p>";

?>


</body>
</html>

2 个答案:

答案 0 :(得分:0)

根据[PHP: end - Manual],当您使用end()时,它会将数组中的最后一个元素作为引用传递。

你可以尝试一些事情:

  1. 请勿在{{1​​}}中使用explode()。声明end()时,请尝试进行爆炸:
    $name

  2. 使用$name = explode( '.', $_FILES['img']['name'] );array_slice()代替list()
    end()

  3. 任何一个都可能有用。

答案 1 :(得分:0)

你得到&#39;注意:未定义的变量&#39;错误,因为您尝试使用变量而不首先初始化它。在您的HTML中,您使用的是#fulltarget&#39;,但它仅在您提交表单后设置。如果你想摆脱这个通知,你应该在你的PHP开头标记之后添加$fulltarget = '';之类的内容。

如果要检查PHP end()函数文档http://php.net/manual/en/function.end.php,您将看到该函数将数组作为参数通过引用。要修复此错误,您应将explode()结果保存为变量,然后将该变量传递给end()函数。例如:$arr = explode('.', $name); $ext = end($arr);