2013-02-13 3 views
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"; 
?> 

코드는 작동하지만 내 관리자 폴더의 새 "이미지"폴더를 만들어야합니다. 나는. 나는 그것이 매우 혼란 알고있다 "관리자 폴더 외부에 파일을 업로드하고 원래의"이미지 "폴더로 이동 할 수있는 방법이 있습니까하지만 내 디렉토리는 다음과 같습니다.이미지를 기존 폴더에 업로드 PHP

clubmaru -images -admin

-css 는 -js

+0

어디서나 원하는 위치로 이동할 수 있습니다. 문제를 이해하지 못합니다. –

+0

그냥 $ add = "../ images"; 또는 (C : \ user \ images) 또는 linux/home/user/public_html/images –

+1

과 같은 실제 경로를 사용하십시오.이 스크립트는 위험합니다. 프로덕션 시스템에 설치하면 완벽한 원격 손상으로 서버가 열리기 때문에 보안상의 결함으로 가득차 있습니다. 이 코드는 사용하지 마십시오. –

답변

1
당신은 PHP의 찾고있을 수 있습니다

이름을 변경 -images 기능. http://php.net/manual/en/function.rename.php

oldname 매개 변수를 파일 (경로 포함) 및 newname 매개 변수를 원하는 위치 (분명히 새 경로와 함께)로 설정하십시오.

파일을 이동하려는 지 확인하십시오 to는 올바른 사용 권한을 설정하여 쓰기 가능하도록합니다. move_uploaded_file에서 매개 변수를 변경하여 파일을 원하는 위치에 배치 할 수도 있습니다.

0

예, 경로가 변경되어야합니다. 지금은 images/$name이라는 경로가 있습니다. 즉, 로컬 디렉토리의 images 디렉토리에있는 파일을 실행중인 스크립트에 저장합니다.

디렉토리 레이아웃을 사용하여이 의미

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

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

당신은 상대 경로를 확인 (또는 다른 대안을 찾기), 디렉토리를 이동 이미지로 다음 CSS로 이동합니다.

관련 문제