0

我在此代码中收到以下错误: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>
4

2 回答 2

0

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

你可以尝试几件事:

  1. 不要explode()end(). 声明时尝试进行爆炸$name
    $name = explode( '.', $_FILES['img']['name'] );

  2. 使用array_slice()andlist()代替end()
    list($ext) = array_slice( explode( '.' , $name ), -1 );

任何一个都可能工作。

于 2013-09-21T06:25:33.107 回答
0

您会收到“注意:未定义的变量”错误,因为您尝试使用变量而不首先对其进行初始化。在您的 HTML 中,您使用“$fulltarget”,但它仅在您提交表单后设置。如果你想摆脱这个通知,你应该$fulltarget = '';在你的 PHP 开始标签之后加上类似的东西。

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

于 2013-09-21T06:36:09.210 回答