Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 网站图像上传问题_Php - Fatal编程技术网

Php 网站图像上传问题

Php 网站图像上传问题,php,Php,最近,我正在开发网站贝克的模块。有一个选项可以上传图像。我正在使用php图像上传代码,但给出以下错误,图像没有上传 Warning: move_uploaded_file(http://localhost/wb/media/gallery/mypic.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in C:\wamp\ww

最近,我正在开发网站贝克的模块。有一个选项可以上传图像。我正在使用php图像上传代码,但给出以下错误,图像没有上传

Warning: move_uploaded_file(http://localhost/wb/media/gallery/mypic.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in C:\wamp\www\wb\modules\hotelmod\save_picture.php on line 84

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpBBBD.tmp' to 'http://localhost/wb/media/gallery/mypic.jpg' in C:\wamp\www\wb\modules\hotelmod\save_picture.php on line 84
以下是我使用的代码:

if (($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg" || $_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/x-png") && ($_FILES["image"]["size"] < 4000000))
    {

        // if uploaded image was JPG/JPEG
        if($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg"){  
            $image_source = imagecreatefromjpeg($_FILES["image"]["tmp_name"]);
        }       
        // if uploaded image was GIF
        if($_FILES["image"]["type"] == "image/gif"){    
            $image_source = imagecreatefromgif($_FILES["image"]["tmp_name"]);
        }   
        // BMP doesn't seem to be supported so remove it form above image type test (reject bmps)   
        // if uploaded image was BMP
        if($_FILES["image"]["type"] == "image/bmp"){    
            $image_source = imagecreatefromwbmp($_FILES["image"]["tmp_name"]);
        }           
        // if uploaded image was PNG
        if($_FILES["image"]["type"] == "image/x-png"){
            $image_source = imagecreatefrompng($_FILES["image"]["tmp_name"]);
        }


        $remote_file =  WB_URL.'/modules/hotelmod/images/'.$_FILES["image"]["name"];
        move_uploaded_file($_FILES['image']['tmp_name'], $remote_file);
}
if($U文件[“图像”][“类型”]=“图像/jpeg”|$$U文件[“图像”][“类型”]=“图像/pjpeg”|$\U文件[“图像”][“类型”]=“图像/gif”|$\U文件[“图像”[“类型”]=“图像/x-png”)&($U文件[“图像”[“图像”][“大小”]<4000000))
{
//如果上传的图像是JPG/JPEG
如果($_文件[“图像”][“类型”]==“图像/jpeg”|$_文件[“图像”][“类型”]==“图像/pjpeg”){
$image\u source=imagecreatefromjpeg($\u文件[“image”][“tmp\u名称]);
}       
//如果上传的图像是GIF
如果($_文件[“图像”][“类型”]=“图像/gif”){
$image\u source=imagecreatefromformgif($\u FILES[“image”][“tmp\u name”]);
}   
//BMP似乎不受支持,因此将其从图像类型测试上方移除(拒绝BMP)
//如果上传的图像是BMP
如果($_文件[“图像”][“类型”]=“图像/bmp”){
$image\u source=imagecreatefromwbmp($\u文件[“image”][“tmp\u名称]);
}           
//如果上传的图像是PNG
如果($_文件[“图像”][“类型”]=“图像/x-png”){
$image\u source=imagecreatefrompng($\u FILES[“image”][“tmp\u name”]);
}
$remote_file=WB_URL.'/modules/hotelmod/images/'.$_文件[“image”][“name”];
移动上传的文件($文件['image']['tmp\u名称],$remote\u文件);
}

我如何解决这个问题?提前谢谢

您可能正在尝试执行以下操作:

move_uploaded_file($_FILES['somefile']['tmp_name'], 'http://localhost/wb/media/gallery/mypic.jpg');
这是不正确的。尝试写入URL只会触发另一个HTTP上载,这是您已经尝试处理的

move_uploaded_files()的目标/目的必须是文件系统路径,如

/home/sites/yoursite/document_root/images/mypic.jpg

相反。

您的目标必须是文件系统路径,而不是URL。由您的web服务器将URL映射到文件系统路径以查找文件(当然,您的脚本需要知道它是如何做到这一点的,以便您可以创建指向它的链接)

例如,您可以将服务器配置为从/srv/www/example.com/uploads/提供服务。然后让PHP脚本将文件移动到/srv/www/example/com/uploads/FOO.png

出于安全原因,请确保关闭上载目录中的PHP(和CGI等)。例如,在Apache中,您可以执行以下操作:

<Directory /srv/www/example.com/uploads>
    php_admin_flag engine off
</Directory>

php_管理_标志引擎关闭

您正在将URL传递到
移动上传的文件()<代码>移动上传的文件()
需要路径。不是URL。可能类似于(对于windows)
C:\path\to\save\uploads

您可以发布一个代码示例吗?这不是正确的代码段您发布的错误没有在路径中包含
/modules/hotelmod/images/