繁体   English   中英

移动上传的文件无法打开流:没有这样的文件或目录 PHP

[英]move uploaded file failed to open stream: No such file or directory PHP

<?php
    if(isset($_FILES['file'])) 
    { 
      
      $original_url='adminPanel/Images/';
      $currentDate = new DateTime();
      $currentTimestamp = $currentDate->format("YmdHis");
      $randomNumber= mt_rand(1111, 9999);
      $filePath=$_FILES['file']['name'];
      $fileName = $currentTimestamp.$randomNumber.$filePath;
      $source = $_FILES['file']['tmp_name'];
      $ext = end((explode(".", $filePath)));//take extension from image/video 
      $fileName = $currentTimestamp.$randomNumber.".".$ext;  
      $original = $original_url.$fileName;  
         move_uploaded_file($source,$original ); 
    }
    
?>

PHP 警告:move_uploaded_file(adminPanel/Images/201704210824047891.JPG):无法打开流:第 19 行的 G:\\PleskVhosts\\sinnonteq.com\\qhawk.sinnonteq.com\\adminPanel\\Product.php 中没有这样的文件或目录

PHP 警告:move_uploaded_file():无法将 'C:\\Windows\\Temp\\phpC5EE.tmp' 移动到 G:\\PleskVhosts\\sinnonteq.com\\qhawk.sinnonteq\\adminPanel\\adminPanel/Images/201704210824047891.JPG' Product.php 第 19 行

很抱歉在编辑之前没有回答问题。

更新答案

检查您使用的文件和位置是否存在是一种很好的做法。

您可以使用is_file()检查文件是否存在或使用is_uploaded_file()检查文件是否存在,如果源文件存在,则通过 HTTP POST 上传。

您可以使用is_dir()检查目标文件夹是否存在。

如果它不存在,您可以先使用mkdir()创建它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM