【问题标题】:Can't upload an image to the server in Godaddy server while its working fine on the local server (xampp)在本地服务器(xampp)上正常工作时,无法将图像上传到 Godaddy 服务器中的服务器
【发布时间】:2020-08-19 09:26:07
【问题描述】:

为什么我不能将图像上传到 Godaddy 服务器中的服务器,而它在本地服务器 (xampp) 上工作正常。这是我的代码:

<?php
session_start();
error_reporting(0);
`include('includes/config.php');`
if(strlen($_SESSION['login'])==0)
  { 
header('location:index.php');
}
else{
if(isset($_POST['submit']))
  {
$testimonoial=$_FILES["fileToUpload"]["name"];
$email=$_SESSION['login'];
$imagetmp=addslashes (file_get_contents($_FILES['fileToUpload']['tmp_name']));
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],"domuents/img/".$_FILES["fileToUpload"]["name"]);
$sql="INSERT INTO  tbltestimonial(UserEmail,imagename,mytmp) VALUES(:email,:testimonoial,:imagetmp)";
$query = $dbh->prepare($sql);
$query->bindParam(':testimonoial',$testimonoial,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':imagetmp',$imagetmp,PDO::PARAM_STR);

$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId)
{
$msg="تم تحميل الوثسقة بنجاح";
}
else 
{
$error="حدث خطا ما . الرجاء اعادة المحاولة";
}

}
?>

这是我的表单代码

<form method="post" enctype="multipart/form-data">
   <div class="form-group">
      <h5 class="uppercase underline">تحميل وثائق</h5>
      <input type="file" name="fileToUpload" class="btn" required>
      <span class="angle_arrow">
          <i class="fa fa-angle-right" aria-hidden="true"></i>
      </span>
      <input type="submit" value="Upload" name="submit" class="btn" style="margin:28px">
   </div>
</form>

我在 phpmyadmin 数据库中使用 godaddy 主机和域。 我搜索了很多但什么也没有,我也试图删除移动到文件夹文本,什么也没有。 我检查了表格是否仍然与本地服务器具有相同的文本并且一切正常。 任何帮助将不胜感激

【问题讨论】:

  • 您的应用程序是否打印了一些错误?也许文件的大小问题已发送。或者目标路径不存在或不可写。
  • 检查任何文件夹是否有大写字母,我遇到过这样的问题,文件夹是 Documents,但我在代码中有文档
  • @TaariqSolomons 是的,一切都很好,所有文件夹都与代码中的相同。
  • @Inazo 一切都很好。
  • 同时检查权限错误

标签: php html mysql godaddy-api


【解决方案1】:

文件夹domuents/img/ 是否存在于您的godaddy 主机上?特别注意你有一个错字domuents,而我猜你想要documents

【讨论】:

  • 是的,它存在,和我输入的一样
  • 如果您在代码var_dump($_FILES); die('stopped'); 中执行,例如在$testimonoial=$_FILES["fileToUpload"]["name"]; 行之前,您会得到任何内容还是空数组?
  • array(1) { ["fileToUpload"]=> array(5) { ["name"]=> string(36) "28fa4e453cc452fa284db32d716f33f9.png" ["type"]=> string( 9) "image/png" ["tmp_name"]=> string(14) "/tmp/phpzxkYsu" ["error"]=> int(0) ["size"]=> int(69733) } } 这就是错误
  • 这不是错误,而是 $_FILES 数组的转储,它向我们表明我们确实拥有该文件。所以现在用var_dump(file_exists("domuents/img/")); var_dump(is_dir("domuents/img/")); var_dump(is_writable("domuents/img/"));替换添加的行你应该得到“true true true”的结果,如果有什么不同,那就意味着文件夹不存在或不可写。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 2013-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
相关资源
最近更新 更多