Php 如何修复此错误消息警告:move_uploaded_file()要求参数1为字符串

Php 如何修复此错误消息警告:move_uploaded_file()要求参数1为字符串,php,html,jquery,Php,Html,Jquery,我是新的PHP,我得到了一个项目,必须与分类广告网站。。现在,我想如果任何用户上传图像,无论大小大小,它应该调整到750x450我得到下面的代码,这对我来说是可行的,但得到了上面的错误 问题是如何调整图像大小并将扩展名返回为.png而不出现任何错误,使用下面的格式帮助我改进 //表格 <div class="dashboard-wrapper"> <p>Browse image files to upload for the Ad <b>&

我是新的PHP,我得到了一个项目,必须与分类广告网站。。现在,我想如果任何用户上传图像,无论大小大小,它应该调整到750x450我得到下面的代码,这对我来说是可行的,但得到了上面的错误

问题是如何调整图像大小并将扩展名返回为.png而不出现任何错误,使用下面的格式帮助我改进

//表格

<div class="dashboard-wrapper">
<p>Browse image files to upload for the Ad <b><?php echo $ad_title; ?></b><br>All images must have a dimension of <strong>(750 X 450)</strong></p>
<?php require 'constants/check_reply.php'; ?>
<form action="app/send-image.php" method="POST"  enctype="multipart/form-data">
   <input   accept="image/*"   type='file' onchange="readURL(this);" required name="image" /><br><br>
   <input type="hidden" name="uploadlink" value="<?php echo $add_id; ?>">
   <img id="blah"class="image-preview" src="../assets/img/blank.png" alt="Image Preview" /><br><br>
   <button class="btn btn-common" name="submit" type="submit">Upload</button>
   <script>
      function readURL(input) {
                if (input.files && input.files[0]) {
                    var reader = new FileReader();
      
                    reader.onload = function (e) {
                        $('#blah')
                            .attr('src', e.target.result);
                    };
      
                    reader.readAsDataURL(input.files[0]);
                }
            }
          
   </script>
</form>

浏览要上载广告的图像文件
所有图像的尺寸必须为(750 X 450)




因为您正在移动resourceId而不是文件。 首先移动上传的文件,然后使用它

// after $file = $_FILES["image"]["tmp_name"]; put this code:
$tmp = './tmp_path/'.$_FILES['image']['name'];
move_uploaded_file($file, $tmp);
$file = $tmp;

//注释行:移动上传的文件($targetLayer,$target\u file.$ext)

您是否尝试移动上传的文件($targetLayer,$target_file......$ext)-您的var$ext只保留扩展名,没有前一个句点。此处相同imagepng($targetLayer,$target_file....$ext);等等此函数返回一个资源标识符,而不是字符串。当我尝试此$targetLayer、$target_文件时,会出现以下错误。$ext。。。警告:imagejpeg(../../uploads/ads/AD33697047/AD3369704704102020091013。):无法打开流:第55行C:\xampp\htdocs\market\user\app\send-image.php中的权限被拒绝警告:move\u uploads\u file()预期参数1为字符串,第71行C:\xampp\htdocs\market\user\app\send-image.php中提供的资源已成功调整图像大小。如何使图像保留此.././在使用用户唯一id自动创建的目录上上载/ads/AD3369704704102020091013,扩展名为.png..$stmt=$conn->prepare(“插入tbl_ads”)(广告id,作者,标题,类别,城市,广告条件,价格,简短描述,固定,品牌,描述,发布日期)值(:adid,:author,:title,:category,:city,:adcond,:price,:shortdesc,:fixed,:brand,:description,:datepost);$stmt->bindParam(':adid',$ad\id);$stmt->bindParam(':author',$myid);$stmt bindParam(':title',$ad\title)$stmt->bindParam(':category',$adu category);$stmt->bindParam(':city',$adu city);$stmt->bindParam(':adcond',$condition);$stmt->bindParam(':price',$price);$stmt->bindParam(':shortdesc',$short_desc);$stmt bindParam(':fixed',$fixed);$stmt->bindParam(':brand',$brand);$stmt bindParam(':description',$desc;$stmt->bindParam(“:datepost',$datepost”);mkdir(“../../uploads/ads/$ad_id”);标题(“位置:../ad-images?节点=$ad_id”);我的代码只是一个正确的示例,因为您误解了上载和操作文件的基本功能。正如我所述:1.将上载的tmp文件移动到带有上载文件名的tmp路径中。2.根据需要处理移动的文件。这非常简单。不要害怕。
// after $file = $_FILES["image"]["tmp_name"]; put this code:
$tmp = './tmp_path/'.$_FILES['image']['name'];
move_uploaded_file($file, $tmp);
$file = $tmp;