0

I'm not a php programmer. Someone ask me help for a web server with problem. I fix everything and update PHP 5.4 to 5.6. Everything work fine on his php program, except file upload.

Message: getimagesize(var/www/myserver/admin/uploads/temp/test.jpg): failed to open stream: No such file or directory

error on this line: $img_info = getimagesize("uploads/temp/$filename");

    if($_POST['fileselect'][0] != "")
        $filename=$_POST['fileselect'][0];
    else
        $filename=$_POST['dragfile'];


    if(strlen($filename) > 3){
        $finalname=time(); //Set a unique filename by the UNIX time

        //Convert to jpg if tiff
        $img_info = getimagesize("uploads/temp/$filename");
        if($img_info['mime'] == "image/tiff"){
                $clearname=explode(".", "$filename")[0];
                system("convert uploads/temp/\"$filename\"[0] uploads/temp/$clearname.jpg");
                unlink("uploads/temp/$filename");
                $filename=$clearname.".jpg";
        }

The problem probably come from a new code formulation in php5.6, any idea how to fix that ?

UPDATE 2: FILE UPLOAD section...

part of form.php

<form method="post" class="form-horizontal">            
<input type="hidden" id="to_upload" name="to_upload" value="/upload.php">
        <input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000000" />
        <input type="hidden" id="id_produit" name="id_produit" value="<?php echo $this->mdl_inventory->form_value('idproduit'); ?>" />
            <div class="control-group">
                <label class="control-label">Nouveau (jpeg): </label>
                <div class="controls">
                    <input type="file" id="fileselect" name="fileselect[]">
                </div>
            </div>

Does the name fileselect[] can be the problem ? How can i check if the script go in "upload.php" ?

part of upload.php

/* read the source image */
    $source_image = imagecreatefromjpeg("$src");
    $width = imagesx($source_image);
    $height = imagesy($source_image);
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);

    if ($fn) {
        // AJAX call
        file_put_contents(
            'uploads/temp/' . $fn,
            file_get_contents('php://input')
        );

        echo "$fn uploaded";
        exit();
    }else {
        // form submit
        $files = $_FILES['fileselect'];
        foreach ($files['error'] as $id => $err) {
            if ($err == UPLOAD_ERR_OK) {
                $fn = $files['name'][$id];
                move_uploaded_file(
                    $files['tmp_name'][$id],
                    'uploads/' . $fn
                );
                echo "<p>File $fn uploaded.</p>";
            }
        }
    }

ajax script filedrag.js (upload)

(function() {

    // getElementById
    function $id(id) {
        return document.getElementById(id);
    }


    // output information
    function Output(msg) {
        var m = $id("messages");
        m.innerHTML = msg + m.innerHTML;
    }


    // file drag hover
    function FileDragHover(e) {
        e.stopPropagation();
        e.preventDefault();
        e.target.className = (e.type == "dragover" ? "hover" : "");
    }


    // file selection
    function FileSelectHandler(e) {

        // cancel event and hover styling
        FileDragHover(e);

        // fetch FileList object
        var files = e.target.files || e.dataTransfer.files;

        // process all File objects
        for (var i = 0, f; f = files[i]; i++) {
            ParseFile(f);
            UploadFile(f);
        }

    }


    // output file information
    function ParseFile(file) {

        Output(
            "<p>File information: <strong>" + file.name +
            "</strong> type: <strong>" + file.type +
            "</strong> size: <strong>" + file.size +
            "</strong> bytes</p>"
        );

        // display an image
        if (file.type.indexOf("image") == 0) {
            var reader = new FileReader();
            reader.onload = function(e) {
                Output(
                    "<p><strong>" + file.name + ":</strong><br />" +
                    '<img src="' + e.target.result + '" /></p>'
                );
            }
            reader.readAsDataURL(file);
        }

        // display text
        if (file.type.indexOf("text") == 0) {
            var reader = new FileReader();
            reader.onload = function(e) {
                Output(
                    "<p><strong>" + file.name + ":</strong></p><pre>" +
                    e.target.result.replace(/</g, "&lt;").replace(/>/g, "&gt;") +
                    "</pre>"
                );
            }
            reader.readAsText(file);
        }

    }


    // upload JPEG files
    function UploadFile(file) {

        // following line is not necessary: prevents running on SitePoint servers
        if (location.host.indexOf("sitepointstatic") >= 0) return

        var xhr = new XMLHttpRequest();
        if (xhr.upload && (file.type == "image/jpeg" || file.type == "image/tiff" ) && file.size <= $id("MAX_FILE_SIZE").value) {

            // create progress bar
            var o = $id("progress");
            var progress = o.appendChild(document.createElement("p"));
            progress.appendChild(document.createTextNode("upload " + file.name));


            // progress bar
            xhr.upload.addEventListener("progress", function(e) {
                var pc = parseInt(100 - (e.loaded / e.total * 100));
                progress.style.backgroundPosition = pc + "% 0";
            }, false);

            // file received/failed
            xhr.onreadystatechange = function(e) {
                if (xhr.readyState == 4) {
                    progress.className = (xhr.status == 200 ? "success" : "failure");
                }
            };
            // start upload
            xhr.open("POST", $id("to_upload").value + "?idproduit=" + $id("id_produit").value, true);
            xhr.setRequestHeader("X_FILENAME", file.name);
            xhr.send(file);

            $('#dragfile').attr('value', file.name);
        }

    }


    // initialize
    function Init() {

        var fileselect = $id("fileselect"),
            filedrag = $id("filedrag"),
            submitbutton = $id("submitbutton");

        // file select
        fileselect.addEventListener("change", FileSelectHandler, false);

        // is XHR2 available?
        var xhr = new XMLHttpRequest();
        if (xhr.upload) {

            // file drop
            filedrag.addEventListener("dragover", FileDragHover, false);
            filedrag.addEventListener("dragleave", FileDragHover, false);
            filedrag.addEventListener("drop", FileSelectHandler, false);
            filedrag.style.display = "block";

            // remove submit button
            //submitbutton.style.display = "none";
        }

    }

    // call initialization file
    if (window.File && window.FileList && window.FileReader) {
        Init();
    }


})();
13
  • i forgot to say, the php.ini is the same, no change. Commented Apr 26, 2017 at 12:50
  • 3
    use the full root path /home/blabla/blabla/. Commented Apr 26, 2017 at 12:50
  • 1
    have you checked to see if the file exists? var/www/myserver/admin/uploads/temp/test.jpg Commented Apr 26, 2017 at 12:51
  • 2
    @RiggsFolly that’s valid syntax since PHP 5.4, see stackoverflow.com/questions/1459377/… Commented Apr 26, 2017 at 12:54
  • looks like permission issue. try setting proper permissions to the respective folders & files Commented Apr 26, 2017 at 12:55

2 Answers 2

0

The syntax for the code mentioned is correct for 5.6, no issues with that.
I don't see permissions as the issue as well, otherwise you'd have gotten a 'Permission denied' error.

So, most likely, it looks like, the file that you are looking for does not exist in the folder.

Sign up to request clarification or add additional context in comments.

Comments

0

the error was here: xhr.setRequestHeader("X_FILENAME", file.name);

X-filename... i think it's APACHE UPDATE problem.

Thanks for help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.