我正在尝试将上传的文件移动到图片文件夹中。在脚本方面我没有遇到任何错误。我使用godaddy作为主持人。所有文件权限都已正确设置。真的不知道还能做什么。
这是php代码:
<?php
public function CheckPicture($picture){
if(empty($_FILES['picture']['name'])){
echo "Must choose a file.";
}else{
$allowed = array('jpg', 'jpeg', 'png');
$file_name = $_FILES['picture']['name'];
//line 157->$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['picture']['tmp_name'];
if(in_array($file_extn, $allowed)){
$this->UploadPicture($username, $file_name, $file_extn);
}else{
echo $file_extn;
echo "Incorect file type. Types allowed: ";
echo implode(', ' , $allowed);
}
}
}
public function UploadPicture($username, $file_temp, $file_extn){
ini_set('display_errors',1);
error_reporting(E_ALL);
$file_path = '/home/content/49/11554349/html/gb/dev/images/pictures/' . substr(md5(time()), 0 , 9) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
echo $file_path;
print_r("$file_temp");
}
?>
这就是我在html中调用它的方式:
<?php
session_start();
include_once('post.php');
$username = unserialize($_SESSION["username"]);
$email = $_SESSION["email"];
if(!$_SESSION["username"]){
header("Location: http://www.greenboardapp.com/dev/");
}
if(isset($_FILES['picture'])){
$upload = new Post();
$upload->CheckPicture($picture);
}
?>
这是表格:
<div class="tile">
<img src="images/profileimg.png" alt="Tutors" class="tile-image">
<form action="profile.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="picture"><br>
<h6><input type="submit" value="Change Profile Pic" class="btn btn-hg btn-success"></h6>
</form>
</div>
答案 0 :(得分:0)
问题是,end
需要引用,因为它修改了数组的内部表示(它使当前元素指针指向最后一个元素)。
explode('.', $file_name)
的结果无法转换为引用。这是PHP语言中的限制,可能出于简单原因而存在。
Strict Standards: Only variables should be passed by reference
Fatal error: Only variables can be passed by reference
Process exited with code 255.
Success
查找
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $picture['tmp_name'];
更改为:
$file_extn_ex = explode('.', $file_name);
$file_extn_end = end($file_extn_ex);
$file_extn = strtolower($file_extn_end);
$file_temp = $picture['tmp_name'];