gpt4 book ai didi

php - 将上传的文件移动到php的文件夹中

转载 作者:行者123 更新时间:2023-11-29 23:42:29 25 4
gpt4 key购买 nike

我使用下面的代码将图像更新到表中,它可以很好地更新图像,但是在检索图像时,路径显示正确,但图像没有显示在页面中。请用上面的内容指导我

if(isset($_FILES['file'])){
$errors= array();
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_tmp =$_FILES['file']['tmp_name'];
$file_type=$_FILES['file']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['file']['name'])));

$expensions= array("jpg","png","gif");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"C:\wamp\www\Mr.bazaar\images\ ".$file_name);
echo "Success";
}else{
print_r($errors);
}
}


$a=$_POST['pids'];
echo $a;
$b=$_FILES['file']['name'];
echo $b;
$qry1=mysql_query("update brand set image='$b' where brand='$a'");

if($qry1)
echo "<script>alert('Your image Sucessgully Uploaded.');</script>";
else
echo "<script>alert('try again');</script>";

我使用下面的代码在页面中显示图像,但它没有在页面中显示

$result = mysql_query("select b_id,brand,image from brand"); 

while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table

echo '<tr>';

echo '<td>';
echo $row['brand'];
echo '</td><td>';
echo '<img height="30" width="60" src=../../images/';
echo $row['image'];
echo '>';

echo '</td>';


}

最佳答案

您的上一个代码中没有对图像的引用。假设,循环应如下所示:

while ($row = mysql_fetch_array($result)) {
$product = $row['brand'];
$image = $row['image'];
echo "<option value=\"$product\">$image</option>";
}

关于php - 将上传的文件移动到php的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26093083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com