PHP文件上传返回错误

朝北

我正在尝试使以下php文件上传脚本正常工作,我已经在所有变量上使用了var_dump()和print_r,据我所知它应该可以工作。实际上,这在我的Windows安装中正在运行...,我当前正在运行Ubuntu 12.04,由于某种原因,它在我的本地安装程序中将不起作用,并且我不愿意尝试运行它,因为这可能是我的/ tmp /问题。权限?

<?php
    function upload() {
        /*     * * check if a file was uploaded ** */
        if (is_uploaded_file($_FILES['images']['tmp_name']) && getimagesize($_FILES['images']['tmp_name']) != false) {
            /*         * *  get the image info. ** */
            $size = getimagesize($_FILES['images']['tmp_name']);
            /*         * * assign our variables ** */
            $type = $size['mime'];
            $imgfp = fopen($_FILES['images']['tmp_name'], 'rb');
            $size = $size[3];
            $name = $_FILES['images']['name'];
            $maxsize = 99999999;
            $target_path = "/uploads/";
            /* Add the original filename to our target path.  
              Result is "uploads/filename.extension" */
            $currentDate = date("Y-m-d");
            $target_path = $target_path . $currentDate . ' - ' . basename($_FILES['images']['name']);
            /*         * *  check the file is less than the maximum file size ** */
            if ($_FILES['images']['size'] < $maxsize) {
                                if (move_uploaded_file($_FILES['images']['tmp_name'], $target_path)) {
                    echo "The file " . basename($_FILES['images']['name']) .
                    " has been uploaded";

                } else {
                    echo "<div class='error'>There was an error uploading the file, please <a href='../artworkGenerator'>try again!</a></div>";
                }
            } else {
                /*             * * throw an exception if image is not of type ** */
                throw new Exception("File Size Error");
            }
        } else {
            // if the file is not less than the maximum allowed, print an error
            throw new Exception("Unsupported Image Format!");
        }
        print_r();
    }

    /* * * check if a file was submitted ** */
    if (!isset($_FILES['images'])) {
        echo '<p>Please select a file</p>';
    } else {
        try {
            upload();
            /*         * * give praise and thanks to the php gods ** */
            echo '<p>Thank you for submitting</p>';
        } catch (Exception $e) {
            echo '<h4>' . $e->getMessage() . '</h4>';
        }
    }
    ?>

上载表格:

<form id="uploadForm" enctype="multipart/form-data" action="upload.php" method="POST">  


                                <input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
                                <label>Attach file<span class="required"> *</span></label><img style="display:none;float:right;position: relative;top: 45px;right: 5px;" class="logo" src="img/tick.png" alt="logo" />
                                <hr class="small"/>
                                <br/>
                                <input type="file" name="images" id="images" multiple />
                                <ul id="image-list">  
                                </ul> 
                                <br/><br/>
                           <hr style="clear:both">
                        <input class="btn btn-success save" type="submit" id="btn" value="Generate"/>

                        <div id="invisible" style="display:none;">
                        </div>
                    </form>
月亮公民

您是否尝试过相对于执行此操作的php文件创建上传路径?

也可能是权限错误,因此请快速检查chmod 777您尝试保存到的文件夹

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

PHP文件上传部分上传错误

来自分类Dev

PHP中的文件上传错误。

来自分类Dev

文件上传应用程序从PHP文件返回内部服务器错误

来自分类Dev

快递文件上传返回400错误

来自分类Dev

在PHP中上传的文件不返回功能

来自分类Dev

在PHP中上传的文件不返回功能

来自分类Dev

上传文件php时返回false

来自分类Dev

php文件上传总是上传文件,即使出现错误

来自分类Dev

非常奇怪的PHP文件上传错误

来自分类Dev

在php中处理文件上传的众多错误

来自分类Dev

PHP文件上传抛出错误

来自分类Dev

AFHTTPRequestOperationManager文件上传返回500服务器错误

来自分类Dev

使用Plupload上传后,Vimeo API返回“文件错误”

来自分类Dev

使用PHP脚本上传文件时出现无效文件错误

来自分类Dev

Powershell-Sharepoint自动文件上传返回“远程服务器返回错误:(403)禁止。” 错误

来自分类Dev

流星:文件上传错误

来自分类Dev

Android文件上传错误

来自分类Dev

多文件上传错误

来自分类Dev

多文件上传错误

来自分类Dev

Ruby上传文件错误

来自分类Dev

上传文件错误

来自分类Dev

Cloudinary文件上传错误

来自分类Dev

上传文件(附件)错误

来自分类Dev

文件上传错误?

来自分类Dev

PHP的文件大小返回统计失败错误

来自分类Dev

ajax如何从PHP文件返回错误消息

来自分类Dev

PHP文件上传未上传

来自分类Dev

我从 iOS 和 Postman 用 PHP 上传文件时出现部分文件上传错误

来自分类Dev

php中的上传文件一直说413错误