【问题标题】:Upload not works correctly, on new server php上传无法正常工作,在新服务器 php 上
【发布时间】:2012-06-26 21:18:02
【问题描述】:

我真的不明白这里发生了什么,它在大多数服务器上都有效,但现在我不能让它工作,我不知道会发生什么。

<?php

 require_once dirname(dirname(dirname(__FILE__)))."/inc/config.php";
 require_once dirname(dirname(dirname(__FILE__)))."/inc/class.upload.php";
 $upload_folder = dirname(__FILE__);


  if(isset($_POST['filename'])) {

$context = stream_context_create(array('http' => array('header'=>'Connection: close')));
$content = file_get_contents($_POST['file'], false, $context);
$fileName = $_POST['filename'];
$ext = substr($fileName, strrpos($fileName, '.') + 1);
$saved_file = str_replace( '.' . $ext, '', $fileName );
$saved_file .= '_' . crypt($saved_file) . '.' . $ext;
$saved_file = str_replace('/', '', $saved_file);
while( @ file_exists($upload_folder.'/'.$saved_file) ) {
    $saved_file = str_replace( '.' . $ext, '', $saved_file );
    $saved_file .= crypt($saved_file) . '.' . $ext;
}


 if(file_put_contents($upload_folder.'/'.$saved_file, $content, 0, $context)) {

    $file_name_save = $upload_folder.'/'.$saved_file;
    $handle = new Upload($file_name_save);

    if ($handle->uploaded){
        $imageName = $handle->file_src_name;
        $handle->file_new_name_body     = date("Ymdhis").md5($imageName);
        $handle->mime_check             = true;
        $handle->allowed                = array('image/*');
        $handle->image_convert          = 'jpg';

        if(($handle->image_src_x > 900) || ($handle->image_src_y > 900)){
            $handle->image_resize   = true;
            $handle->image_ratio    = true;
            $handle->image_x        = 900;
            $handle->image_y        = 600;
        }

        $handle->Process(dirname(dirname(dirname(__FILE__))).'/img/Noticias/');

        if ($handle->processed){
            $NoticiaFoto_Imagem = $handle->file_dst_name;

            $Sql = "INSERT INTO tabnoticiasfotos (Noticia_Id, NoticiaFoto_Nome, NoticiaFoto_Ordem, NoticiaFoto_Imagem)  VALUES ('".$_POST['ID']."', '', 'NULL', '$NoticiaFoto_Imagem') ";
            fputs($fp,$Sql);
            $Query = mysql_query($Sql,$Conn) or die(mysql_error($Conn));
            @unlink($file_name_save);
        }

    }
}
echo $saved_file;
$_SESSION["varMensagem"]["css"] = "success";
$_SESSION["varMensagem"]["mensagem"] = "Fotos Enviadas com sucesso.";
exit();
 }
?>

这会得到一组图像(jquery 上传)并完成所有工作。

但在新服务器上,没有任何效果

图片上传到文件所在的同一个文件夹,新名称看起来很疯狂,不要在我的数据库中保存任何信息。

我在所有测试之前发布了

问题来了

 if(file_put_contents($upload_folder.'/'.$saved_file, $content, 0, $context)) {

返回 false,所以不要完成上传。

所以对我来说问题就在这里,我认为是关于服务器配置。 $context = stream_context_create(array('http' => array('header'=>'Connection: close')));

对不起,我不是专家

【问题讨论】:

  • “没有任何效果”很好,这很有帮助。你至少得自己调试一下。
  • 一定有一些错误信息 - 检查服务器日志,在脚本顶部添加ini_set('display_errors', 1); error_reporting(E_ALL); 以查看它们记录到屏幕上
  • 您检查过目录的所有权吗?试试阿帕奇
  • 文件上传从什么时候开始使用$_POST?除非您将文件的内容粘贴到文本框中,否则上传信息应该在 $_FILES 中。
  • 会发生什么? "$upload_folder = 目录名(文件);" => "图片上传到同一个文件夹", "$saved_file .= '_' . crypt($saved_file) . '.' . $分机;" => 新名称看起来很疯狂,也许 '$NoticiaFoto_Imagem' 应该有 " insted of ' 所以 var 值被发送到数据库

标签: php file-upload upload


【解决方案1】:
allow_url_fopen = On 

解决了问题。

【讨论】:

    猜你喜欢
    • 2013-08-10
    • 2011-02-27
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 2017-06-02
    • 2014-04-03
    • 2012-08-02
    • 1970-01-01
    相关资源
    最近更新 更多