[ad_1]
Mais cette récupération du code image ne fonctionne pas
Ce que j’ai essayé :
C’est mon accueil complet. php dans lequel l’utilisateur modifie sa photo de profil et voit les détails de son profil.
<?php include('config.php');?> <?php // index.php session_start(); if(!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } $username = $_SESSION['username']; $sql = "SELECT * FROM services WHERE user_name = '".$_SESSION['username']."'"; $result = $con->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { ?> <!-- Save username and profile picture--> <link rel="stylesheet" type="text/css" href="css/welcome_php.css"> <?php include('header.php');?> <div class="container"> <div class="row"> <div class="col-md-7 "> <div class="panel panel-default"> <div class="panel-heading"> <a style="float: right" href="logout.php">class="fa fa-sign-out"> Logout</a> <center> <h4 >User Profile</h4></center> </div> <div class="panel-body"> <div class="box box-info"> <div class="box-body"> <div class="col-sm-6"> <form method="post" action="ajaxupload.php" enctype="multipart/form-data"> <h5 style="color:#a66a6a;">Set your profile picture</h5> <input type="file" name="Filename"> <input type="hidden" name="Description" value="<?php echo $row ['user_name']; ?>" /> <br/> <input TYPE="submit" name="upload" value="Submit" class="btn1" /> </form> </div> <div class="col-sm-6"> <h4 style="color:#a66a6a;"><?php echo $row ['name']; ?></h4></span> <span><p><?php echo $row ['service']; ?></p></span> </div> <div class="clearfix"></div> <hr style="margin:5px 0 5px 0;"> <div class="col-sm-5 col-xs-6 tital " >Name</div><div class="col-sm-7 col-xs-6 "><?php echo $row ['name']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >User Name</div><div class="col-sm-7"> <?php echo $row ['user_name']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >Password</div><div class="col-sm-7"> <?php echo $row ['password']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >email</div><div class="col-sm-7"><?php echo $row ['email']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >District</div><div class="col-sm-7"><?php echo $row ['district']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >City</div><div class="col-sm-7"><?php echo $row ['city']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >Address</div><div class="col-sm-7"><?php echo $row ['address']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >Service</div><div class="col-sm-7"><?php echo $row ['service']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >Years</div><div class="col-sm-7"><?php echo $row ['years']; ?></div> <div class="clearfix"></div> <div class="bot-border"></div> <div class="col-sm-5 col-xs-6 tital " >Details</div><div class="col-sm-7"><?php echo $row ['details']; ?></div> <center><a href="update_userinfo.php" class="btn" role="button">Update</a></center> <?php } } ?> <?php $sql="SELECT image_path FROM images where user_name = '".$_SESSION['username']."'"; $result = $con->query($sql); $file_name=$row['file_name']; $image_path=$row['image_path'];//here you get path where you store image for user1 ?> <img src=<?php echo"$image_path";?> width=500 height=400> <br>
Il s’agit d’un fichier de téléchargement ajax qui enregistre l’image dans la base de données.
<?php $fileExistsFlag = 0; $fileName = $_FILES['Filename']['name']; $link = mysqli_connect("localhost","root","","construction") or die("Error ".mysqli_error($link)); /* * Checking whether the file already exists in the destination folder */ $query = "SELECT file_name FROM images WHERE file_name='$fileName'"; $result = $link->query($query) or die("Error : ".mysqli_error($link)); while($row = mysqli_fetch_array($result)) { if($row['filename'] == $fileName) { $fileExistsFlag = 1; } } /* * If file is not present in the destination folder */ if($fileExistsFlag == 0) { $target = "uploads/"; $fileTarget = $target.$fileName; $tempFileName = $_FILES["Filename"]["tmp_name"]; $fileDescription = $_POST['Description']; $result = move_uploaded_file($tempFileName,$fileTarget); /* * If file was successfully uploaded in the destination folder */ if($result) { echo "Your file <html>".$fileName."</html> has been successfully uploaded"; $query = "INSERT INTO images(image_path,file_name,user_name) VALUES ('$fileTarget','$fileName','$fileDescription')"; $link->query($query) or die("Error : ".mysqli_error($link)); } else { echo "Sorry !!! There was an error in uploading your file"; } mysqli_close($link); } /* * If file is already present in the destination folder */ else { echo "File <html>".$fileName."</html> already exists in your folder. Please rename the file and try again."; mysqli_close($link); } ?>
Solution 1
En plus de mon commentaire sur le fait de ne montrer aucun code contenant le img_src
variable.
Les valeurs des attributs HTML doivent être entre guillemets (les navigateurs les acceptent généralement également sans guillemets mais ce n’est pas du HTML valide) et doivent être entre guillemets si elles contiennent des espaces ou des caractères réservés :
<?php echo '<img src="' . $image_path . '" width="500" height="400">'; ?>
[EDIT]
Ce code semble avoir été copié et collé et ne fonctionnera pas comme prévu :
$sql="SELECT image_path FROM images where user_name = '".$_SESSION['username']."'"; // Executing the query and assigning to $result // OK so far but it misses checking for errors $result = $con->query($sql); // What is $row? // The query result has been stored in $result! // There is probably something missing like //$row = $result->fetch_row(); // Finally, the above SQL query returns only one field: image_path // So 'file_name' will never be present $file_name=$row['file_name']; $image_path=$row['image_path'];//here you get path where you store image for user1
Si ce qui précède a été corrigé pour renvoyer un chemin depuis la base de données (ou imprimer des commentaires sinon), le chemin peut être utilisé pour le img
à condition que les fichiers existent et soient un chemin relatif à la racine du document du serveur Web (commençant par “https://www.codeproject.com/”) ou relatif à la page actuelle.
[/EDIT]
Solution 2
je
<?php $sql="SELECT * FROM images where user_name = '".$_SESSION['username']."'"; $result = $con->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { ?> <?php echo '<img src="' . $row['image_path']. '" width="500" height="400">'; ?> <?php } } ?>
[ad_2]
コメント