PHP move_uploaded_file不工作但没有错误?

时间:2013-12-05 07:32:05

标签: php

我正在尝试将上传的文件移动到图片文件夹中。在脚本方面我没有遇到任何错误。我使用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>

1 个答案:

答案 0 :(得分:0)

问题是,end需要引用,因为它修改了数组的内部表示(它使当前元素指针指向最后一个元素)。

explode('.', $file_name)的结果无法转换为引用。这是PHP语言中的限制,可能出于简单原因而存在。

5.1.0的输出 - 5.5.6

Strict Standards: Only variables should be passed by reference

输出5.0.5

Fatal error: Only variables can be passed by reference
Process exited with code 255.

4.3.0 - 5.0.4的输出

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'];