4
내 서버의 프로필/디렉토리에 파일을 업로드하려고하는데 모든 작업이 정상적으로 작동 할 수도 있습니다. 그러나 업로드시 내 jpeg png 및 gif가 올바른 파일 유형이 아니라고 생각됩니다. 왜 이렇게하고있는거야? 여기 뭐가 잘못 됐니? 어떻게 고칠 수 있니?모든 이미지 확장자가 PHP로 허용되지 않습니까?
function change_profile_image($user_id, $file_temp, $file_extn) {
$file_path = 'profile/' . substr (md5(time()), 0, 10) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
mysql_query("UPDATE `users` SET `profile` = " . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int)$user_id);
}
if (isset($_FILES['profile']) === true) {
if (empty($_FILES['profile']['name']) === true) {
echo 'y u no choose file!';
} else {
$allowed = array ('jpg', 'jpeg', 'gif', 'png');
//this is the part i think may be brocken.
$file_name = $_FILES['profile']['name'];
$file_extn = strtolower(end(explode (' . ', $file_name)));
$file_temp = $_FILES['profile']['tmp_name'];
if (in_array($file_extn, $allowed) === true) {
change_profile_image($session_user_id, $file_temp, $file_extn);
header('Location: dontdelete.php');
exit();
}else {
echo 'y u no jpg or png or gif';
}
}
}
if (empty($user_data['profile']) === false) {
echo '<img src"', $user_data['profile'], '" alt="">';
}
는 [*'mysql_로 사용하지 마십시오 새로운 코드에서'기능 (HTTP : //stackoverflow.com/q/12859942). 그것들은 더 이상 유지 보수되지 않으며 비추천 프로세스가 시작되었습니다. [red box] (http://php.net/mysql-connect)를보십시오. 대신 [준비된 진술] (http://en.wikipedia.org/wiki/Prepared_statement)에 대해 알아보십시오. –
결국 도전적 일 것입니다! – user1775570