2017-07-14 124 views
0

在这里查看一些答案,但似乎没有任何工作.. 我是新来的PHP,并尝试从jQuery的Bootbox对话框内的窗体上传多个文件。 。PHP表单不提交(等待本地主机...)

这里是我的形式:

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 

好奇的是,它调用PHP脚本只是max_input_time..then后回声对剧本的beggining警报,并给出了错误

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

有人能帮忙吗?

编辑: 阿帕奇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

+0

什么是'max_execution_time'?在你的** php.ini **中。可能是你正在尝试上传需要时间的大文件。设置'max_execution_time'为'0'然后尝试 –

+0

参考此链接 - https://stackoverflow.com/questions/29916516/wampserver-phpmyadmin-maximum-execution-time-of-360-seconds-exceeded可能会有所帮助。 – KMS

+0

@ B.Desai做到了,仍然没有工作......并且文件是200kb – alvarosps

回答

0

做的修改按链接WAMPServer phpMyadmin Maximum execution time of 360 seconds exceeded。你重新启动了wamp服务器吗? 还是会出现同样的错误?

给我发送错误的详细信息。

+0

如何获取错误详细信息?我得到了唯一的错误很多时间后,它是最大的执行时间... 我使用XAMPP,而不是WAMP,它没有phpmyadmin.config文件..但设置是相似的,并作出了改变,并仍然不工作.. @ KMS – alvarosps

+0

编辑与错误日志的帖子... – alvarosps