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");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料