php 上传图片问题
<?php
//This is the directory where images will be saved
if(! is_dir("./temp/"))
{
mkdir("./temp/");
@chmod("./temp/",777);
}
$target = "./temp/";
$target = $target . basename( $_FILES['photo']['name']);
$img=($_FILES['photo']['name']);
require_once('config.php');
// Connect to server and select databse.
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)or die("cannot connect");
mysql_select_db(DB_DATABASE)or die("Cannot select database.");
$IncidentName = $_POST['name'];
//The date of the incident
$Day = $_POST['Day'];
$Month = $_POST['Month'];
$Year = $_POST['Year'];
$dateOfIncident = $Day."/".$Month."/".$Year;
$Type = $_POST['Type'];
$Location = $_POST['Location'];
$Impact = $_POST['Impact'];
if (!$_POST["name"]) {
die("Please enter incident name.");
}
$sql="Insert INTO disasterup (name,time,type,location,impact,picsad) Values ('$IncidentName', '$dateOfIncident','$Type','$Location','$Impact','$img')";
$result=mysql_query($sql);
if($result){
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file has been uploaded, and your information has been added to the directory";
}
else
{
echo "Some problem happened to upload your picture or file!";
} }
else {
echo "Inserting into disaster table failed ";
}
?>
之前本来能用的 过了一段时间 源文件丢了 就剩下错的这个 不管怎得都不能传 本地文件 求高手指教啊 速度啊 目前运行后 其他数据都可以录入 唯独图片地址和move那块有问题
答案:二进制上传只是FTP的一种上传模式,只是为了保证文件的完整性。估计你的PHP模板是加密过的,所以你看不了源码。我就有个这样的经验,我们公司买了一个PHP软件就是用ionCube,必须要装ionCube loader 才可以运用。但是源码还是看不到。
如果你下载的PHP模板是用ionCube加密的,你可以参照我写的文章来运行:
不知道你需要什么样的CMS模板,如果你只是要学习PHP,那么我认为在网上应该很容易找到没有加密的PHP源码。
另外,虚机团上产品团购,超级便宜
其他:$result=mysql_query($sql)这里执行的是插入语句 而插入语句是没有返回值的
所以你的if($result)也就不会执行
使用if(mysql_affected_rows()>0)表示的是上一次操作影响的行数 1,图片地址是$target,不是$img,SQL语句里写错了。$img=$_FILES['photo']['name'],是上传时的临时文件。
2,可以试试把 move_uploaded_file 函数改成用 copy 函数。 错误提示? 到“第一php网”的“网站开发代码库”,搜索:“批量上传”
上一个:php问题报错信息为:
下一个:php中用于改变字符集编码的函数是什么