我的上传脚本仅适用于我的计算机

时间:2014-03-26 11:56:38

标签: php mysql

我的上传脚本仅在我的网络中的计算机上100%工作,当使用其他网络(另一个位置)时,它将图像上传到ftp服务器,但它不会在Mysql db中保存其标题。看起来它无法从其他位置访问数据库。 这是代码:

session_start();

require 'config2.php';
require_once 'user.class.php';

 $target = "sent/"; 
 $target1 = "sent/";
 $target2 = "sent/";
  $target3 = "sent/";
$target4 = "sent/";
$target5 = "sent/";

$target = $target . basename( $_FILES['photo']['name']); 
$target1 = $target1 . basename( $_FILES['photo1']['name']); 
$target2 = $target2 . basename( $_FILES['photo2']['name']);
$target3 = $target3 . basename( $_FILES['photo3']['name']);
$target4 = $target4 . basename( $_FILES['photo4']['name']);
$target5 = $target5 . basename( $_FILES['photo5']['name']);

  //This gets all the other information from the form 
$login = $_SESSION['login'];    
$name=$_POST['name']; 
$name1 =$_POST['name1'];
 $name2 =$_POST['name2'];
$name3 =$_POST['name3'];
$name4 =$_POST['name4'];
$name5 =$_POST['name5'];
$pic=($_FILES['photo']['name']); 
$pic1=($_FILES['photo1']['name']); 
$pic2=($_FILES['photo2']['name']); 
$pic3=($_FILES['photo3']['name']); 
$pic4=($_FILES['photo4']['name']); 
$pic5=($_FILES['photo5']['name']); 

$id=$_SESSION['id'];
// Connects to your Database 

  mysql_query("UPDATE users SET name='$name', name1='$name1', name2='$name2', name3='$name3', name4='$name4', name5='$name5', photo = '$pic', photo1 = '$pic1', photo2 = '$pic2', photo3 = '$pic3', photo4 = '$pic4', photo5 = '$pic5' WHERE  login = '$login' ");


$allowed = array('jpg', 'jpeg', 'gif', 'png');  

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'] ,$target) )
{ 




  //Tells you if its all ok 
echo "Plik ". basename( $_FILES['photo']['name'] ). " uploaded successfuly"; 
echo implode(', ', $allowed);
} 


f(move_uploaded_file($_FILES['photo1']['tmp_name'] ,$target1) )
{ 

 //Tells you if its all ok 
 echo "Plik ". basename( $_FILES['photo1']['name'] ). " uploaded successfuly"; 
echo implode(', ', $allowed);
 } 

if(move_uploaded_file($_FILES['photo2']['tmp_name'] ,$target2) )
 { 

//Tells you if its all ok 
 echo "Plik ". basename( $_FILES['photo2']['name'] ). " uploaded successfuly"; 
echo implode(', ', $allowed);
 } 

if(move_uploaded_file($_FILES['photo3']['tmp_name'] ,$target3) )
{ 

//Tells you if its all ok 
echo "Plik ". basename( $_FILES['photo3']['name'] ). " uploaded successfuly"; 
echo implode(', ', $allowed);
 } 

 if(move_uploaded_file($_FILES['photo4']['tmp_name'] ,$target4) )
 { 

 //Tells you if its all ok 
 echo "Plik ". basename( $_FILES['photo4']['name'] ). " uploaded successfuly"; 
echo implode(', ', $allowed);
} 

if(move_uploaded_file($_FILES['photo5']['tmp_name'] ,$target5) )
{ 

//Tells you if its all ok 
 echo "Plik ". basename( $_FILES['photo5']['name'] ). " uploaded successfuly"; 
 echo implode(', ', $allowed);

你知道怎么解决吗?也许你可以看到错误/每一个欢迎帮助。

1 个答案:

答案 0 :(得分:1)

使用

创建目标路径
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$target = $docRoot."/sent/". basename( $_FILES['photo']['name']);;

并检查服务器上的文件夹权限