0

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

<?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')));

对不起,我不是专家

4

1 回答 1

-1
allow_url_fopen = On 

解决了这个问题。

于 2012-06-26T22:09:57.183 回答