move_uploaded_file无法在服务器端运行

时间:2022-03-01 16:14:17

I write my php and html code, it was not working while hosting on the server.

我写了我的PHP和HTML代码,它在服务器上托管时无法正常工作。

<form class="form-horizontal style-form"   enctype="multipart/form-data" method="post"   action="insert.php">

                  <div class="form-group">
                          <label class="col-sm-2 col-sm-2 control-label"> Name *</label>
                          <div class="col-sm-4">
                              <input type="text" required="" class="form-control" id="sname" name="sname"/>
                          </div>

                            <label class="col-sm-2 col-sm-2 control-label">Upload *</label>
                          <div class="col-sm-4">
                              <input type="file" class="form-control" id="Filename" required="" name="file"/>
                          </div> 
                      </div>  
                          <div class="col-sm-8" > </div>
                          <div class="col-sm-2">
                         <input type="submit"  class="btn btn-theme" name="softsubmit" value="Submit">

                          </div>
                         </form>  

and my insert.php file is:

我的insert.php文件是:

<?php 
if(isset($_POST['softsubmit'])) 
{ 
$sname=$_POST['sname'];
$file_name = $_FILES['file']['name']; 
$file_size =$_FILES['file']['size']; 
$file_tmp =$_FILES['file']['tmp_name']; 
$file_type=$_FILES['file']['type']; 
$tmp="uploads/".$file_name; 
$ok = move_uploaded_file($file_tmp,$tmp);
if($ok == true)
 echo 'success';
  else
   echo 'error';
  }

ERROR:

错误:

"move_uploaded_file(): Unable to move '/tmp/phpkEr7JN' to '/home/novasoftco/public_html/adminuploads/TNEB Online Payment.zip'"

“move_uploaded_file():无法将'/ tmp / phpkEr7JN'移动到'/ home / novasoftco / public_html / adminuploads / TNEB Online Payment.zip'”

1 个解决方案

#1


0  

You have given the relative path for destination

您已经给出了目的地的相对路径

You need to specify the absolute path to the function. move_uploaded_file()

您需要指定函数的绝对路径。 move_uploaded_file()以

The following line will help you

以下行将对您有所帮助

$tmp = dirname(__FILE__) . "/uploads/" . $file_name;
$ok  = move_uploaded_file($file_tmp, $tmp);

move_uploaded_file never creates the folder itself, so you need to create the folder uploads manually.

move_uploaded_file从不创建文件夹本身,因此您需要手动创建文件夹上载。

Also set the uploads folder permission to 755

同时将uploads文件夹权限设置为755

#1


0  

You have given the relative path for destination

您已经给出了目的地的相对路径

You need to specify the absolute path to the function. move_uploaded_file()

您需要指定函数的绝对路径。 move_uploaded_file()以

The following line will help you

以下行将对您有所帮助

$tmp = dirname(__FILE__) . "/uploads/" . $file_name;
$ok  = move_uploaded_file($file_tmp, $tmp);

move_uploaded_file never creates the folder itself, so you need to create the folder uploads manually.

move_uploaded_file从不创建文件夹本身,因此您需要手动创建文件夹上载。

Also set the uploads folder permission to 755

同时将uploads文件夹权限设置为755