从本地主机到网络主机时文件上传问题
如何在互联网上上传图像?现在,下面的脚本可以在本地主机上运行,但在托管时我遇到问题。有人有什么想法吗?
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个可能的问题是您没有写入目标目录的权限!
请向您的提供商核实您是否能够这样做。您可能必须设置 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.
您应该会收到一条错误消息来解释您的问题。 情况下会阻止 PHP 错误消息,并且可以使用以下代码在运行时重新启用这些消息:
我假设正在运行 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:
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.