0

Looked over some answers here but nothing seems to work.. I'm new to PHP and trying to upload multiple files from a form that's inside a jquery bootbox dialog..

here's my form:

function dialogUpload() {
    bootbox.confirm({
        message:  '<form name="uploadForm" action="Control/upload.php" method="post" enctype="multipart/form-data"> '
                + '     Nome do objeto:<br />'
                + '     <input name="objectname" type="text"><br />'
                + '     <input type="hidden" name="MAX_FILE_SIZE" value="10000000">'
                + '     Objeto 3D(Formato <b>.dae</b>):<br />'
                + '     <input name="userfile[]" type="file" /><br />'
                + '     Imagem 2D do objeto(Formato <b>.png</b> ou <b>.jpg</b>) (<i>Opcional</i>):'
                + '     <input name="userfile[]" type="file" /><br />'
                + '     Comentário:<br />'
                + '     <textarea name="comment" rows="5" cols="75"></textarea>'
                + '</form>',
        buttons: {
            confirm: {
                label: 'Enviar Arquivo',
                className: 'btn-success'
            },
            cancel: {
                label: 'Cancelar',
                className: 'btn-danger'
            }
        },
        callback: function (result) {
            if(result){
                document.uploadForm.submit();
            }
        }
    });
}

and heres my PHP, it just create a random file name and check the file extensions...than upload the file to respective folder. Running on Windows 10, with XAMPP(don't know if it's relevant)

<?php
include '../Model/conexao.php';
include 'funcoes.php';


echo '<script>alert("Upload script started.");</script>';
$uploadIsOk = TRUE;

$imageUploaded = FALSE;

$targetObjectDirectory = "C:\xampp\htdocs\importaobjetos\uploads\objects";
$targetImageDirectory = "C:\xampp\htdocs\importaobjetos\uploads\images";

$fileName = createFileName($targetObjectDirectory);

$targetObjectFile = $targetObjectDirectory . basename($_FILES["userfile"][0]["name"]);
$targetObjectFileType = pathinfo($targetObjectFile, PATHINFO_EXTENSION);

if($_FILES["userfile"][1]["name"] != ""){
    $targetImageFile = $targetObjectDirectory . basename($_FILES["userfile"][1]["name"]);
    $targetImageFileType = pathinfo($targetImageFile,PATHINFO_EXTENSION);
    $imageUploaded = TRUE;
}


$errorMessage = '<script>alert("';
$successMessage = '<script>alert("';

checkExtensions();
replaceOriginalFileName();

if(!$uploadIsOk){
    $errorMessage = $errorMessage . 'Erros occoridos estão acima, upload não foi feito.';
    $errorMessage = $errorMessage . '");</script>';
    echo $errorMessage;
}
else{
    //Tudo certo, fazer upload

    if(move_uploaded_file($_FILES["userfile"][0]["tmp_name"], $targetObjectFile)){
        $successMessage = $successMessage . 'Upload do objeto foi feito com sucesso.\n';
        if($imageUploaded && move_uploaded_file($_FILES["userfile"][1]["tmp_name"], $targetImageFile))
            $successMessage = $successMessage . 'Upload da imagem foi feito com sucesso.\n';
    }

    $successMessage = $successMessage . '");</script>';
    echo $successMessage;
}


//Funcoes

function checkExtensions(){
    echo '<script>alert("checkExtensions");</script>';
    if($targetObjectFileType != "dae"){
        $uploadIsOk = FALSE;
        $errorMessage = $errorMessage . 'Formato invalido para o objeto, favor usar arquivos .dae\n';
    }

    if($imageUploaded){
        if($targetImageFileType != "jpg" && $targetImageFileType != "jpeg" && $targetImageFileType != "png"){
            $uploadIsOk = FALSE;
            $errorMessage = $errorMessage . 'Formato invalido para a imagem, favor usar arquivos .jpg, .jpeg ou .png\n';
        }
    }
}

function createFileName($targetObjectDirectory){
    $fileCreated = FALSE;
    echo '<script>alert("createFileName");</script>';
    while(!$fileCreated){
        $fileName = "";
        $size = mt_rand(5,9);
        $all_str = "abcdefghijlkmnopqrstuvxyzwABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        for ($i = 0;$i <= $size;$i++){
            $fileName .= $all_str[mt_rand(0,61)];
        }

        $filePath = $targetObjectDirectory . $fileName . '.dae';

        if(checkIfExists($filePath))
            $fileCreated = TRUE;
    }

    return $fileName;
}

function checkIfExists($filePath){
    if(file_exists($filePath))
        return TRUE;
    else
        return FALSE;
}

function replaceOriginalFileName(){
    $targetObjectFile = $targetObjectDirectory . $fileName . '.' . $targetObjectFileType;
    if(imageUploaded)
        $targetImageFile = $targetImageDirectory . $fileName . '.' . $targetImageFileType;
    else
        $errorMessage = $errorMessage . 'Voce nao fez upload da imagem, será utilizada a imagem padrao.';
}

?>

things I've changed in php.ini to try to make it work...:

file_uploads = On
upload_max_filesize = 10M
max_file_uploads = 20
post_max_size = 10M
max_input_time = 360

The curious thing is that it calls the php script just after the max_input_time..then it echos the alert on the beggining of the script, and gives the error

Fatal error: Maximum execution time of 360 seconds exceeded in C:\xampp\htdocs\importaobjetos\Control\upload.php on line 113

someone can help?

EDIT: Apache errors.log(from last trial)

[Fri Jul 14 10:34:29.219240 2017] [ssl:warn] [pid 5864:tid 664] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Jul 14 10:34:29.275767 2017] [core:warn] [pid 5864:tid 664] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Fri Jul 14 10:34:29.332850 2017] [ssl:warn] [pid 5864:tid 664] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Jul 14 10:34:29.354372 2017] [mpm_winnt:notice] [pid 5864:tid 664] AH00455: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 configured -- resuming normal operations
[Fri Jul 14 10:34:29.354372 2017] [mpm_winnt:notice] [pid 5864:tid 664] AH00456: Apache Lounge VC11 Server built: Dec 20 2016 13:02:04
[Fri Jul 14 10:34:29.354372 2017] [core:notice] [pid 5864:tid 664] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Fri Jul 14 10:34:29.355874 2017] [mpm_winnt:notice] [pid 5864:tid 664] AH00418: Parent: Created child process 4944
[Fri Jul 14 10:34:29.754780 2017] [ssl:warn] [pid 4944:tid 632] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Jul 14 10:34:29.929697 2017] [ssl:warn] [pid 4944:tid 632] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Jul 14 10:34:29.953227 2017] [mpm_winnt:notice] [pid 4944:tid 632] AH00354: Child: Starting 150 worker threads.
[Fri Jul 14 10:34:42.508930 2017] [:error] [pid 4944:tid 1920] [client ::1:54421] PHP Notice:  Trying to get property of non-object in C:\\xampp\\htdocs\\importaobjetos\\index.php on line 152
[Fri Jul 14 10:34:42.509446 2017] [:error] [pid 4944:tid 1920] [client ::1:54421] PHP Notice:  Trying to get property of non-object in C:\\xampp\\htdocs\\importaobjetos\\index.php on line 162

when i try to get php_error_log it gives me "the system cannot find the path specified"

alvarosps
  • 83
  • 1
  • 11
  • What is `max_execution_time`? in your **php.ini** . May be you are trying to upload large file which takes time. set `max_execution_time` to `0` then try – B. Desai Jul 14 '17 at 12:46
  • refer this link - https://stackoverflow.com/questions/29916516/wampserver-phpmyadmin-maximum-execution-time-of-360-seconds-exceeded May it help. – KMS Jul 14 '17 at 12:48
  • @B.Desai did it, still not working...and the file is 200kb – alvarosps Jul 14 '17 at 12:58
  • @KMS, did both changes in the file, still not working ;/ – alvarosps Jul 14 '17 at 12:58

1 Answers1

0

Do the changes as per the link WAMPServer phpMyadmin Maximum execution time of 360 seconds exceeded. Did you restarted the wamp server? Or still same error coming?

Send me the error details.

KMS
  • 566
  • 4
  • 16
  • How to get error details? The only error I get after a lot of time it's the max execution time... I'm using XAMPP, not WAMP, it doesn't have the phpmyadmin.config file..but the settings is similar and made the changes, and still not working.. @KMS – alvarosps Jul 14 '17 at 13:12