0

現在、アップロード、サイズ変更、トリミングのスクリプトに取り組んでいます。URL から画像をコピーしてサーバーに保存するのに問題があります。

これは、エラーが発生する私のコードです。ドメインを [MYDOMAIN] に置き換えました。

if(in_array($extension, $extensions_allowed) )
{
    $name = explode(".".$extension, $_FILES['image']['name']);
    $name = $name[0]."_".time();

    move_uploaded_file($_FILES['image']['tmp_name'], "temp/".$name.".".$extension);
    // File uploaded to temporary folder, now lets replace the newly created temp image with a resized image
    $source = 'timthumb.php?src=http://[MYDOMAIN]/includes/crop/temp/'.$name.'.'.$extension.'&w=398';   // Set source to be the resized image
    $dest = $_SERVER['DOCUMENT_ROOT'].'/includes/crop/temp/r'.$name.'.'.$extension;                             // Destination = temp folder, rdy to be cropped.
    if(copy($source, $dest)) {
        // If the image was transfered/copied successfully
        unlink("temp/".$name.".".$extension);   // Remove old temp img. "not the resized"
        // The old one has been removed, so now the new file can take its place, lets rename it.
        $current = 'temp/r'.$name.'.'.$extension;
        $new = 'temp/'.$name.'.'.$extension;
        rename($current, $new); // Old temp name becomes the new.
    }
    else {
        echo "Couldnt copy file, try again.";
        die();
    }


    $_SESSION['image']['extension'] = $extension;
    $_SESSION['image']['name'] = $name;
    //REDIRECT ON SUCCESS
    header("Location: /includes/crop/edit.php");
}

私はそれが機能していることを知っているので、完全なコードを書く必要はないと思います。

だから私のmove_uploaded_files()作品はうまくいきますが、すぐ下のif文でエラーが発生します。

if(copy($source, $dest)) {
    // If the image was transfered/copied successfully
    unlink("temp/".$name.".".$extension); // Remove old temp img. "not the resized"
    // The old one has been removed, so now the new file can take its place, lets rename it.
    $current = 'temp/r'.$name.'.'.$extension;
    $new = 'temp/'.$name.'.'.$extension;
    rename($current, $new);   // Old temp name becomes the new.
}
else {
    echo "Couldnt copy file, try again.";
    die();
}

私のエラーメッセージ:

警告: copy(timthumb.php?src= http://[MYDOMAIN]/includes/crop/temp/SummerVibe Cover_1389227432.jpg&w=398): ストリームを開けませんでした: No such file or directory in /home/[MYHOST]/ 108 行目の public_html/pt/includes/crop/index.php

ファイルをコピーできませんでした。もう一度お試しください。

行 108 がどこにあるのか疑問に思っている場合は、それが のif(copy(ect))開始行です。

誰かが助けてくれることを願っています。:)

よろしくお願いします、SmK1337

4

1 に答える 1

0

あなたのエラーは、相対パスをphpスクリプトにコピーしようとしているということです(または、かなり古い質問です)。( timthumb.php?src=...)

初めに。エラーは、このパスが存在しないことを意味します。これには、主に次の 2 つの理由が考えられます。

  1. timthumb.phpは相対パスです。これは、php が現在の作業ディレクトリに対して相対的に解決しようとすることを意味します。これは、スクリプトの実行方法によって異なる場合があります。
  2. ファイルを実行するのではなく、ファイルの実際の内容をコピーしようとします。これは確かにあなたが望むものではありません。
  3. ?src=は、実際のクエリ文字列ではなく、ファイル名の一部です。確かに、このファイルは存在しません

timthumb.php代わりにすべきことは、 http 経由でスクリプトにリクエストを送信することです。

copyhttp 経由でファイルをコピーできます。その場合 (正しく構成された Web サーバー上の php スクリプトである場合)、ファイルが実行されます。

copy('http://[MYDOMAIN]/path/to/timthumb/script/' . $source, $dest);
于 2017-11-03T08:17:15.770 に答える