将图像上传到远程服务器。 PHP [英] Upload images to remote servers. PHP

查看:97
本文介绍了将图像上传到远程服务器。 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做图像托管,但我遇到了问题..

I do the image hosting and I have a problem..

我有3台服务器。

第一个 - 网站/脚本

First - Site/script

任意两个图像服务器。

我如何从一个上传图像服务器(脚本)到第二和第三台服务器?

How I Can upload image from "one" server (script) to second and third servers?

<?php
    if (isset($_POST['upload']))
    {
        $blacklist = array('.php', '.phtml', '.php3', '.php4', '.php5');
        foreach ($blacklist as $item)
        {
            if(preg_match('#' . $item . '\$#i', $_FILES['file']['name']))
            {
                echo "We do not allow uploading PHP files\n";
                exit;
            }
        }

        $uploadDir  = PROJECT_ROOT . 'upload/'; // 1ST SERVER (THIS SERVER)
        $uploadFile = $uploadDir . basename($_FILES['file']['name']);

        if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile))
        {
            echo "File is valid, and was successfully uploaded.\n";
        }
        else
        {
            echo "File uploading failed.\n";
        }
    }    
?>
<form name="upload" method="post" enctype="multipart/form-data">
    Select the file to upload: <input type="file" name="file"/>
    <input type="submit" name="upload" value="upload"/>
</form>


推荐答案

您可以使用ftp。 PHP有相当简单的方法来做到这一点。查看此链接。

You could use ftp. PHP has fairly easy way to do this. Check this link.

http://www.php.net/manual/en/book.ftp.php

这篇关于将图像上传到远程服务器。 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆