0
<?php
include('includes/db.php');

$drinks_cat = $_POST['drinks_cat'];
$drinks_name = $_POST['drinks_name'];
$drinks_shot = $_POST['drinks_shot'];
$drinks_bottle = $_POST['drinks_bottle'];
$drinks_availability = 'AVAILABLE';

$msg = "ERROR: ";
$itemimageload="true";
$itemimage_size=$_FILES['image']['size'];
$iname = $_FILES['image']['name'];
if ($_FILES['image']['size']>250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload.<BR>";
$itemimageload="false";}

if (!($_FILES['image']['type'] =="image/jpeg" OR $_FILES['image']['type'] =="image/gif" OR $_FILES['image']['type'] =="image/png"))
{$msg=$msg."Your uploaded file must be of JPG , PNG or GIF. Other file types are not allowed<BR>";
$itemimageload="false";}

$file_name=$_FILES['image']['name'];
$add="images"; // the path with the file name where the file will be stored


if($itemimageload=="true")
{
    if (file_exists($add) && is_writable($add)) 
    {
        if(move_uploaded_file ($_FILES['image']['tmp_name'], $add."/".$_FILES['image']['name']))
        {
        echo "Image successfully updated!";
        }
        else
        {
        echo "Failed to upload file Contact Site admin to fix the problem";
        }
    }
    else 
    {
    echo 'Upload directory is not writable, or does not exist.';
    }
}
else
{
    echo $msg;
}

$dir = $add."/".$iname;
echo "<BR>";
// Connects to your Database



mysql_query("INSERT INTO `product_drinks`(`drinks_id`, `drinks_cat`, `drinks_name`, `drinks_shot`, `drinks_bottle`, `drinks_image`, `drinks_availability`) VALUES (NULL,'".$drinks_cat."', '".$drinks_name."','".$drinks_shot."','".$drinks_bottle."','".$dir."','".$drinks_availability."')") or die("insert error");

Print "Your table has been populated";
?>

私が取り組んでいるコードは機能しますが、管理フォルダー用に新しい「画像」フォルダーを作成する必要があります。admin フォルダの外にあるファイルをアップロードして元の「image」フォルダに移動する方法はありますか? 非常に紛らわしいことはわかっていますが、私のディレクトリは次のようになっています。

clubmaru -admin -images

-css -画像 -js

4

2 に答える 2

1

PHPの名前変更関数を探している可能性があります。http://php.net/manual/en/function.rename.php

oldnameパラメーターを(そのパスとともに)ファイルに設定し、newnameパラメーターを(明らかに新しいパスとともに)目的の場所に設定します。

ファイルを移動する「画像フォルダ」に正しい権限が設定されていることを確認してください。書き込み可能であることを確認してください。また、 move_uploaded_fileのパラメーターを変更して、最初に必要な場所にファイルを配置することを検討することもできます。

于 2013-02-13T19:09:32.760 に答える
0

はい、方法があります。パスを変更する必要があります。images/$nameこれは、実行中のスクリプトのローカル ディレクトリにある images ディレクトリにファイルを配置することを意味します。

ディレクトリ レイアウトの使用:

clubmaru
  ->admin
    ->script.php (the upload file)
    ->images
  ->css
    ->images
      ->js

パスを相対的にします(または別の代替手段を見つけます)

$add="../css/images";

これは、ディレクトリを上に移動し、css に移動してから画像に移動することを意味します。

于 2013-02-13T19:10:03.370 に答える