0

im currently having an issue with the upload of files from the mobile version of the site im currently working with, I think the issue is related to the fact that the mobile version files are outside the public_hmtl folder inside a folder named m, this was done like this because the m.site.com link wouldnt work otherwise, since im using the classic site folder to store all the media, the problem starts here:

heres the path im working with:

  • /
  • /m
  • /public_html

the file in

  • /m/user/fnc/upload.php

is directed to save an img to

  • /public_html/photos/users/

here's a fragment of the code in upload.php for the first line, I use a redirect variable called $img that leads to the index of the classic version, that would be

  • www.mysite.com/

so

$URL = $img.'photos/users/';
$NewFotoName = "misite_".$usuarioid."_".time().".jpg";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $imagen = $_POST['Imagen'];
    if ( isset($_POST['Imagen']) ) {
        $image = base64_decode($imagen);
        $im = imagecreatefromstring($image);
        imagepng($im,$URL.$NewFotoName);
        imagedestroy($im);

        $query = "UPDATE Utenti SET foto = '$NewFotoName' WHERE id_utente = ".$usuarioid;
        $result = $mysqli->query($query);
        if(!$result){die($mysqli->error);}
        echo "index2.php";
                die();
    } else {
        echo "index2.php";
                die();          
    }
} else {
    echo "index2.php";
                die();
}

and i call it from a file one folder above it called index2.php with this code:

$('.upload-result').on('click', function (ev) {
            $uploadCrop.croppie('result', {
                type: 'canvas',
                size: 'original'
            }).then(function (resp) {
                $('#imagebase64').val(resp);
                var imagen_cortada = $('#imagebase64').val();
                var base64image = imagen_cortada;
                var parametros = { "Imagen" : base64image };
                $.ajax({
                    data: { "Imagen" : output },
                    url: 'fnc/upload.php',
                    method: 'POST', // or GET
                    success: function(msg) 
                    {
                        alert("Imagen subida con exito.");
                        alert(msg);
                    },
                    error: function (jqXHR, textStatus, errorThrown)
                    {
                        alert("Error al Subir la Imagen.");
                        alert(errorThrown);
                        window.location.replace(msg);
                    }
                });

now when the form is submited I get a succes alert but in the "alert(msg);" I get an error that says

imagepng(path/to/the/file.png): failed to open stream; no such file or directory in /home/mysite/m/user/fnc/upload.php

So the name of the file gets saved into the database but the file doesnt.

I appreciate any suggestions, excuse any spelling mistakes.

//edit I found a work arround and moved the subdomaind directory inside public_html, had to learn a bit about the .htacces, it seems this way i will not have all those pesky permision problems

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Marco Laso
  • 1
  • 1
  • 4
  • then use a full system path. I.e.: `/var/usr/folder_name/` and check permissions – Funk Forty Niner May 20 '16 at 19:10
  • tried using ../../../public_html/photos/user/ as the path but ended up with the same error, also idk about permissions, i read some things about https and cors but i dont think that applies here since its the same domain – Marco Laso May 20 '16 at 19:17
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew May 22 '16 at 18:09

1 Answers1

0

I found a work arround and moved the subdomaind directory inside public_html, had to learn a bit about the .htacces, it seems this way i will not have all those pesky permision problems, the other workarrounds posted in the similar thread Vic Seedoubleyew posted didnt seem to do the trick for me

Marco Laso
  • 1
  • 1
  • 4