duanhuan8983 2013-08-20 19:05
浏览 56
已采纳

将图像上传到服务器但在WAMP服务器上没有错误

I am getting an error while uploading images to my website host. But I don't experience any problems on my WAMP server. This is the error I am getting.

[20-Aug-2013 00:58:27 America/Denver] PHP Warning:  copy(/photos/Light-And-Snow.jpg) [<a href='function.copy'>function.copy</a>]: failed to open stream: No such file or directory in /home/rajeev/public_html/upload.php on line 86

The code on line 86 is

                mysql_query(
                "INSERT INTO
                    gallery_photos (
                `photo_filename`,
        `photo_caption`,
                `photo_description`,
        `photo_keywords`,
                `category_name`
                ) VALUES(
            '".addslashes($photos_uploaded['name'][$counter])."',
                    '".addslashes($photo_caption[$counter])."',
                    '".addslashes($photo_description[$counter])."',
                    '".addslashes($photo_keyword[$counter])."',
                    '".addslashes($_POST['category'])."')"
                ) or die(mysql_error() . 'Photo not uploaded');

            $filetype = $photos_uploaded['type'][$counter];

            $extention = $known_photo_types[$filetype];

// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$photos_uploaded['name'][$counter]);

What am I doing wrong? Thanks for any directions...

  • 写回答

1条回答 默认 最新

  • dshun123456 2013-08-20 19:14
    关注

    It looks like you are trying to save the photos to /photos/ directory on your host. In a shared hosting environment, you will most likely not have access to create folders on the root of the filesystem.

    I'm guessing, you have a line somewhere like

    $images_dir = '/photos';
    

    You need to change this to a relative path instead of an absolute path:

    $images_dir = $_SERVER['DOCUMENT_ROOT'] . '/photos';
    

    You might also have to create that folder and make sure it has permissions for you to write. This can be done through the command line, if you have shell access, or through the admin tool your hosting provider supplies.

    It works on WAMP because you are liking running with relaxed permissions: Apache has permission to create or write to a C:\photos\ directory

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集