php使用move_uploaded_file函数上传文件报错failed to open stream: Invalid argument in解决方案

php使用move_uploaded_file上传文件报错failed to open stream: Invalid argument in 解决方案

先报错failed to open stream: Invalid argument

然后写入失败。

文档编码使用UTF-8

因为用英文名称文件上传,一切正常

代码如下:

<?php
/*
UploadiFive
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
*/

// Set the uplaod directory
$uploadDir = 'uploadify/uploads/';

// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    
    
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
    $targetFile = $uploadDir . $_FILES['Filedata']['name'];

	//关键性代码 转码
    if (function_exists("iconv"))     {
    
    
        $targetFile=iconv("UTF-8","GBK",$targetFile);
    }


    echo $targetFile;
    // Validate the filetype
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
    
    

        // Save the file
        move_uploaded_file($tempFile, $targetFile);
        echo 1;

    } else {
    
    

        // The file type wasn't allowed
        echo 'Invalid file type.';

    }
}
?>

在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/guo_qiangqiang/article/details/114183591
今日推荐