2016-06-11 4 views
1

나는 그것을 수행하는 데 필요한 것보다 상대적으로 쉬운 프로젝트를 진행 해왔다.이미지 업로드 PHP

나는 의사와 환자 사이에있는 전체 웹 사이트를 만들었습니다. 이미지를 업로드하고 검색하는 데 심하게 붙어 있습니다! 여기

는 ..

<?php session_start(); 
 

 
$un = "xxx"; 
 
$pw = "xxx"; 
 
$hn = "xxx"; 
 
$dbhandle = mysql_connect($hn, $un, $pw) or die("Couldn't connect to the database"); 
 
mysql_set_charset('utf8'); 
 
$selected = mysql_select_db("dsnnet_login", $dbhandle); 
 
$myusername = $_SESSION['snamed']; 
 

 

 
$target_dir = "uploaded/"; 
 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
 
$sql = mysql_query("UPDATE docTable set photoname='$target_file' WHERE Username= '$myusername'"); 
 
$uploadOk = 1; 
 
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
 
// Check if image file is a actual image or fake image 
 
if(isset($_POST["submit"])) { 
 
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); 
 
    if($check !== false) { 
 
     echo "File is an image - " . $check["mime"] . "."; 
 
     $uploadOk = 1; 
 
    } else { 
 
     echo "File is not an image."; 
 
     $uploadOk = 0; 
 
    } 
 
} 
 
// Check if file already exists 
 

 
// Check file size 
 
if ($_FILES["fileToUpload"]["size"] > 500000) { 
 
    echo "Sorry, your file is too large."; 
 
    $uploadOk = 0; 
 
} 
 
// Allow certain file formats 
 
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" 
 
&& $imageFileType != "gif") { 
 
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; 
 
    $uploadOk = 0; 
 
} 
 
// Check if $uploadOk is set to 0 by an error 
 
if ($uploadOk == 0) { 
 
    echo "Sorry, your file was not uploaded."; 
 
// if everything is ok, try to upload file 
 
} else { 
 
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
 
     echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
 
    } else { 
 
     echo "Sorry, there was an error uploading your file."; 
 
    } 
 
} 
 

 
header("location: docp.php"); 
 

 
?>

내가 작성했던 코드와 "작업 페이지는"다음과 같다 :

<?php session_start(); 
 

 
$un = "xxx"; 
 
$pw = "xxx"; 
 
$hn = "xxx"; 
 
$dbhandle = mysql_connect($hn, $un, $pw) or die("Couldn't connect to the database"); 
 
mysql_set_charset('utf8'); 
 
$selected = mysql_select_db("dsnnet_login", $dbhandle); 
 
$myusername = $_SESSION['snamed']; 
 

 

 
$target_dir = "uploaded/"; 
 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
 
$sql = mysql_query("UPDATE docTable set photoname='$target_file' WHERE Username= '$myusername'"); 
 
$uploadOk = 1; 
 
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
 
// Check if image file is a actual image or fake image 
 
if(isset($_POST["submit"])) { 
 
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); 
 
    if($check !== false) { 
 
     echo "File is an image - " . $check["mime"] . "."; 
 
     $uploadOk = 1; 
 
    } else { 
 
     echo "File is not an image."; 
 
     $uploadOk = 0; 
 
    } 
 
} 
 
// Check if file already exists 
 

 
// Check file size 
 
if ($_FILES["fileToUpload"]["size"] > 500000) { 
 
    echo "Sorry, your file is too large."; 
 
    $uploadOk = 0; 
 
} 
 
// Allow certain file formats 
 
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" 
 
&& $imageFileType != "gif") { 
 
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; 
 
    $uploadOk = 0; 
 
} 
 
// Check if $uploadOk is set to 0 by an error 
 
if ($uploadOk == 0) { 
 
    echo "Sorry, your file was not uploaded."; 
 
// if everything is ok, try to upload file 
 
} else { 
 
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
 
     echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
 
    } else { 
 
     echo "Sorry, there was an error uploading your file."; 
 
    } 
 
} 
 

 
header("location: docp.php"); 
 

 
?>

누구나 알아낼 수 있습니까? 나는 포기하지 않을거야 지금은 적어도 4 일 동안 노력했습니다 .. .. 나는

너희들 : 환호

+0

당신이 오류를 얻고있다. 또는 죄송합니다. 파일이 너무 큽니다. –

답변

1

체크을 아래에 감사합니다 .. 배울 열려있어

1.tag 양식 로컬 호스트하지 2.if에 enctype = "multipart/form-data"로

는, 폴더 업로드가 777

1

내가 오류 messag을 알 수 permittion을 설정해야이 너는 붙잡 았어?

이전에 양식 enctype 속성을 확인하십시오. 업로드 양식은 다음과 같아야합니다 것과 같은 업로드는 JPG, JPEG, PNG 및 GIF 파일을 사용할 수 있습니다 - 미안를 언급하면서

<form action="upload.php" method="post" enctype="multipart/form-data"> 
 
    Select image to upload: 
 
    <input type="file" name="fileToUpload" id="fileToUpload"> 
 
    <input type="submit" value="Upload Image" name="submit"> 
 
</form>