Я хочу изменить изображение профиля пользователя, когда они нажмут изображение профиля изменения, но оно не работает. Noe ошибки или что-то просто не работает. Я хотел бы изменить изображение профиля в JavaScript или PHPИзменение профиля профиля пользователя PHP
profile.php:
<form id="form2" action="upload.php" method="post" enctype="multipart/form-data">
<p id="p1">Change profile picture:</p> <br />
<input type="file" name="fileToUpload" id="fileToUpload"><br />
<br><input id="sub1" type="submit" value="Change profile picture" name="submit"><br />
</form>
upload.php:
<?php
$target_dir = "C:\wamp\www\TestSocialNetwork\uploads";
//This is the directry where the images will be uploaded, "server_path/uploads"
//Now since we have the target directory, let's define the actual path.
//Actual Path = Target Dir + File Name + File Extension
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
//By now, we have just madefined locations, (in the form of Variables)
//Now, lets do few checks, and make a success flag to keep a track
$uploadOk = 1;
// Check if file already exists
if (file_exists($target_file)) {
//If the file already exists
echo "Sorry, file already exists.";
$uploadOk = 0;
//Echo and change the flag to False
}
// Check if image file is a actual image or fake image.
//If file is image, then only image size will be returned
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if(!($check)) {
//That is, the Check is false, the file is NOT AN IMAGE
echo "File is not an image.";
$uploadOk = 0;
//Echo, and change the Flag to false.
}
//Now check, if the flag is true, that means upload is OK, and NO ERRORS.
//Then upload the file.
if ($uploadOk) {
//If upload is OK, then go ahead
move_uploaded_file($_FILES['image']['tmp_name'], $target_file);
// Move the uploaded file to the desired folder
}
?>
Как ваш HTML знает, где найти изображение для отображения? Фактическое изображение отсутствует в ваших образцах кода. Из того, что я вижу, этот метод не внесет изменений до тех пор, пока страницы не будут обновлены. – ToothlessRebel