警告:chmod():没有这样的文件或目录

时间:2016-01-20 18:28:57

标签: php chmod

好的我有一个php文件,允许我上传一个csv文件,读入数据,并输出我需要的任何内容。我在文件上传部分遇到了问题。

以下是我的全部代码:

brentq(f, a, b, xtol=None, rtol=None,  maxiter=100, full_output=None, disp=None, *args):
    if xtol is None: xtol = 1e-12
    if rtol is None: rtol = 4.4408920985006262e-16
    if full_output is None: full_output = False
    if disp is None: disp = true
    # ... rest of function

然后我收到此错误:

警告:chmod():第56行/var/www/html/report/gocode.php中没有此类文件或目录

我的代码中的第56行是:

define("UPLOAD_DIR", "/tmp/");
# chmod(UPLOAD_DIR, 0777);
// show upload form
if ($_SERVER["REQUEST_METHOD"] == "GET") {
?>
<em>GoCode Upload.</em>

<form action="gocode.php" method="post" enctype="multipart/form-data">
 <input type="file" name="myFile"/>
 <br/>
 <input type="submit" value="Upload"/>
</form>
<?php
}
// process file upload
else if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_FILES["myFile"])) {
    $myFile = $_FILES["myFile"];
    if ($myFile["error"] !== UPLOAD_ERR_OK) {
        echo "<p>An error occurred.</p>";
        #exit;
    }

    // ensure a safe filename
    $name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
    // don't overwrite an existing file
    $i = 0;
    $parts = pathinfo($name);
    while (file_exists(UPLOAD_DIR . $name)) {
        $i++;
        $name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
    }
    // preserve file from temporary directory
    $success = move_uploaded_file($myFile["tmp_name"], UPLOAD_DIR . $name);
    if (!$success) {
        echo "<p>Unable to save file.</p>";
        #exit;
    }
    // set proper permissions on the new filei

    chmod(UPLOAD_DIR . $name, 0777);
    echo "<p>Uploaded file saved as " . $name . ".</p>";
}

$fh = fopen(UPLOAD_DIR . $name, 'r'); // 1
$minutes = 0;
$cost = 0;
if ($fh) { // 2
  while ( ($row = fgetcsv($fh)) !== false ) { // 3
    //print_r($row); // 4
$minutes += $row[0];
$cost += $row[1];
    //echo '<br>';


        }
}
echo "Minutes: ";
echo number_format((float)$minutes, 2, '.', '');
echo '<BR>';
echo "Cost: $";
echo number_format((float)$cost, 2, '.', '');
echo '<BR><BR><BR>';

我最初拥有0644的权限,但是转到了0777,看看是否有效,但它没有。任何帮助表示赞赏。谢谢。

0 个答案:

没有答案