从本地主机到网络主机时文件上传问题

发布于 2024-10-19 23:59:36 字数 1173 浏览 7 评论 0原文

如何在互联网上上传图像?现在,下面的脚本可以在本地主机上运行,​​但在托管时我遇到问题。有人有什么想法吗?

<?php
// form in which we can upload the image
session_start();

include("connect.php");

// session as on website.

$jobseekerid = $_SESSION['jobseekerid'];

if($_POST['submit'])
{
    //get file attributes
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];


    if ($name)
    {
       // start upload process
       $location ="pictures/$name";
       move_uploaded_file($tmp_name,$location);
// updating table users (setting image locaion
       $query = mysql_query("UPDATE jobseekers SET imagelocation='$location' WHERE jobseekerid='$jobseekerid'");

       die("Your avatar has been uploaded! <a href='profile.php'>Go back to view</a>");


    }
    else

        die("Please Select a file!");

}

echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";

echo "Upload Your image:

<form action='upload.php' method='POST' enctype='multipart/form-data'>
File: <input type='file' name='myfile'> <input type='submit' name='submit' value='upload!'
>
</form>

";

?>

How to upload an image on the internet? right now the script below works on local host but i have issues when its hosted. any one have any ideas?

<?php
// form in which we can upload the image
session_start();

include("connect.php");

// session as on website.

$jobseekerid = $_SESSION['jobseekerid'];

if($_POST['submit'])
{
    //get file attributes
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];


    if ($name)
    {
       // start upload process
       $location ="pictures/$name";
       move_uploaded_file($tmp_name,$location);
// updating table users (setting image locaion
       $query = mysql_query("UPDATE jobseekers SET imagelocation='$location' WHERE jobseekerid='$jobseekerid'");

       die("Your avatar has been uploaded! <a href='profile.php'>Go back to view</a>");


    }
    else

        die("Please Select a file!");

}

echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";

echo "Upload Your image:

<form action='upload.php' method='POST' enctype='multipart/form-data'>
File: <input type='file' name='myfile'> <input type='submit' name='submit' value='upload!'
>
</form>

";

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

予囚 2024-10-26 23:59:36

一个可能的问题是您没有写入目标目录的权限!

请向您的提供商核实您是否能够这样做。您可能必须设置 FTP 权限 777 才能上传目录或选择 ISP 提供的其他上传路径。

至少这是最典型的问题。

下次请更好地格式化你的问题。

A possible problem is that you don't have permissions to write into the target directory!!

Please check if you are able to with your provider. You may have to set FTP permissions 777 to upload directory or to choose a different upload path that is given by your ISP.

At least that is the most typical issue.

And please, next time format your questions better.

暮年 2024-10-26 23:59:36

您应该会收到一条错误消息来解释您的问题。 情况下会阻止 PHP 错误消息,并且可以使用以下代码在运行时重新启用这些消息:

ini_set("display_errors", 1);

我假设正在运行 PHP 应用程序的用户组对其托管目录没有写访问权限。

一些共享托管平台默认 在操作系统和托管平台上,有多种方法可以授予这些权限。

You should get an error message explaining your problem. Some shared hosting platforms block PHP error messages by default, and these can be re-enabled at runtime with this code:

ini_set("display_errors", 1);

I am assuming that the usergroup that is running your PHP application does not have write access to the directory it is hosted in.

Depending on the operating system and hosting platform, there are various ways in granting these permissions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文