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

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

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B