doutu6658
2015-08-28 06:05
浏览 25
已采纳

图像文件没有在PHP上传

I am just learning php the way it works and trying to upload the file using move_uploaded_file. The code i have written seems perfect but at the end it is generating a warning message. I am giving my code

<?php

if(isset($_POST['create'])){
$productcatid=$_POST['productcategory'];

$name = ucfirst(trim($_POST['itemname']));
if(isset($_POST['status'])){
$status = true;
}
else{
$status = false;
}
if(isset($_POST['availability'])){
$avalability = true;
}
else{
$avalability = false;
}


$c=$_POST['price'];
$d=$_POST['type'];
$e=$_POST['brandname'];
$f=$_POST['datecreated'];
$g=$_POST['size'];
$h=$_POST['colour'];
$i=$_POST['fabric'];


if(isset($_FILES['upload'])){
    $file = $_FILES['upload'];
    $n = $file['name'];
    $s = $file['size'];
    $tm = $file['tmp_name'];
    $er = $file['error'];
    $target = 'uploadedfiles/'.$n;

    if(move_uploaded_file($tm, $target)){
        $sql = "insert into product_items(item_name, is_active, category_id, image_url, date_created, is_item_available, type, brand_name, fabric, size, colour,price) ";
        $sql .= " values('".$name."','".$status."','".$productcatid."','".$upload."','".$f."','".$avalability."','".$d."','".$e."','".$i."','".$g."','".$h."','".$c."')";
        include('config.php');
        $res = mysql_query($sql);
        if($res){
          //header('Location:allproductitemcategory.php');
          echo 'success';
        }
        else{
          echo mysql_error();
        }
    }
    else{
        echo 'error uploading file. '.$er;
    }
}


}
else{
    echo 'error';
}
?>

It is giving a following warning

Warning: move_uploaded_file(uploadedfiles/s3.jpg) failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/onlineshopping/insertproductitems.php on line 38

Warning: move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/php6TeZrH' to 'uploadedfiles/s3.jpg' in /Applications/XAMPP/xamppfiles/htdocs/onlineshopping/insertproductitems.php on line 38 error uploading file. 0

I am just stuck here as I am not able to get it. Please help

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujiling4377 2015-08-28 06:27
    已采纳

    if your problem is about permission just chmod (change mode) your folder. chmod("yourfolder", "r");

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题