【问题标题】:PHP Form Not Submiting (Waiting for localhost...)PHP 表单未提交(等待本地主机...)
【发布时间】:2017-12-19 13:47:23
【问题描述】:

在这里查看了一些答案,但似乎没有任何效果.. 我是 PHP 新手,正在尝试从 jquery 引导框对话框中的表单上传多个文件..

这是我的表格:

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();
            }
        }
    });
}

这是我的 PHP,它只是创建一个随机文件名并检查文件扩展名...然后将文件上传到相应的文件夹。 在 Windows 10 上运行,使用 XAMPP(不知道是否相关)

<?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.';
}

?>

我在 php.ini 中进行了更改以尝试使其正常工作...:

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

奇怪的是它会在 max_input_time 之后调用 php 脚本。然后它会在脚本开始时回显警报,并给出错误

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

有人可以帮忙吗?

编辑: Apache errors.log(来自上次试用版)

[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

当我尝试获取 php_error_log 时,它给了我“the system cannot find the path specified

【问题讨论】:

  • 什么是max_execution_time?在您的 php.ini 中。可能是您尝试上传需要时间的大文件。将max_execution_time 设置为0 然后尝试
  • 参考此链接 - stackoverflow.com/questions/29916516/… 可能会有所帮助。
  • @B.Desai 做到了,仍然无法正常工作...文件为 200kb
  • @KMS,对文件进行了两次更改,仍然无法正常工作;/

标签: php forms time upload


【解决方案1】:

根据链接WAMPServer phpMyadmin Maximum execution time of 360 seconds exceeded 进行更改。您是否重新启动了 wamp 服务器? 还是会出现同样的错误?

将错误详情发送给我。

【讨论】:

  • 如何获取错误详情?很长时间后我得到的唯一错误是最大执行时间...我使用的是 XAMPP,而不是 WAMP,它没有 phpmyadmin.config 文件..但是设置相似并进行了更改,并且仍然无法正常工作.. @KMS
猜你喜欢
  • 1970-01-01
  • 2011-08-07
  • 1970-01-01
  • 1970-01-01
  • 2015-02-23
  • 2015-07-09
  • 1970-01-01
  • 2011-01-06
  • 1970-01-01
相关资源
最近更新 更多