“没有这样的文件或目录”虽然文件在那里?

时间:2014-10-09 15:54:36

标签: php apache

我收到此错误消息:

    Warning: move_uploaded_file(uploads/1f77f7e78f36847859c0604e9645f112.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\ubergallery\multiple_image_upload\upload.php on line 17

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpE035.tmp' to 'uploads/1f77f7e78f36847859c0604e9645f112.jpg' in C:\xampp\htdocs\ubergallery\multiple_image_upload\upload.php on line 17
1).please try again!.

" upload.php的"包含在" multiupload.php"我希望包含" multiupload.php"里面" index.php"位于这里:

ubergallery/resources/themes/uber-blue/index.php

其他两个文件位于此处:

ubergallery/multiple_image_upload/multiupload.php
ubergallery/multiple_image_upload/upload.php

这是upload.php:

<?php
if (isset($_POST['submit'])) {
    $j = 0; //Variable for indexing uploaded image 

    $target_path = "uploads/"; //Declaring Path for uploaded images
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array

        $validextensions = array("jpeg", "jpg", "png");  //Extensions which are allowed
        $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) 
        $file_extension = end($ext); //store extensions in the variable

        $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];//set the target path with a new name of image
        $j = $j + 1;//increment the number of uploaded images according to the files in array       

      if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded.
                && in_array($file_extension, $validextensions)) {
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else {//if file was not moved.
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
            }
        } else {//if file size and file type was incorrect.
            echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
        }
    }
}
?>

这是index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>Qinter</title>
    <link rel="shortcut icon" href="<?php echo THEMEPATH; ?>/images/favicon.png" />

    <link rel="stylesheet" type="text/css" href="<?php echo THEMEPATH; ?>/rebase-min.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo THEMEPATH; ?>/style.css" />
    <?php echo $gallery->getColorboxStyles(5); ?>

    <script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.min.js"></script>
    <?php echo $gallery->getColorboxScripts(); ?>

    <?php file_exists('googleAnalytics.inc') ? include('googleAnalytics.inc') : false; ?>



    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://localhost/ubergallery/multiple_image_upload/script.js"></script>

    <!-------Including CSS File------>
    <link rel="stylesheet" type="text/css" href="http://localhost/ubergallery/multiple_image_upload/style.css">




</head>
<body>
<div class="imageupload clearfix">
    <?php
    include($_SERVER['DOCUMENT_ROOT']. '/ubergallery/multiple_image_upload/multiupload.php');

    ?>

    </div>


<!-- Start UberGallery v<?php echo UberGallery::VERSION; ?> - Copyright (c) <?php echo date('Y'); ?> Chris Kankiewicz (http://www.ChrisKankiewicz.com) -->
<div id="galleryWrapper">
    <div class="line"></div>

    <?php if($gallery->getSystemMessages()): ?>
        <ul id="systemMessages">
            <?php foreach($gallery->getSystemMessages() as $message): ?>
                <li class="<?php echo $message['type']; ?>">
                    <?php echo $message['text']; ?>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>


    <div id="galleryListWrapper">
        <?php if (!empty($galleryArray) && $galleryArray['stats']['total_images'] > 0): ?>
            <ul id="galleryList" class="clearfix">
                <?php foreach ($galleryArray['images'] as $image): ?>
                    <li><a href="<?php echo html_entity_decode($image['file_path']); ?>" title="<?php echo $image['file_title']; ?>" rel="colorbox"><img src="<?php echo $image['thumb_path']; ?>" alt="<?php echo $image['file_title']; ?>"/></a></li>
                <?php endforeach; ?>
            </ul>
        <?php endif; ?>
    </div>

    <div class="line"></div>
    <div id="galleryFooter" class="clearfix">

        <?php if ($galleryArray['stats']['total_pages'] > 1): ?>
        <ul id="galleryPagination">

            <?php foreach ($galleryArray['paginator'] as $item): ?>

                <li class="<?php echo $item['class']; ?>">
                    <?php if (!empty($item['href'])): ?>
                        <a href="<?php echo $item['href']; ?>"><?php echo $item['text']; ?></a>
                    <?php else: ?><?php echo $item['text']; ?><?php endif; ?>
                </li>

            <?php endforeach; ?>

        </ul>
        <?php endif; ?>


    </div>
</div>
<!-- End UberGallery - Distributed under the MIT license: http://www.opensource.org/licenses/mit-license.php -->

</body>
</html>

我希望你能帮忙解决错误信息。

No such file or directory in C:\xampp\htdocs\ubergallery\multiple_image_upload\upload.php on line 17

该文件肯定存在。

2 个答案:

答案 0 :(得分:1)

在这种情况下,

No Such File or Directory很可能意味着源文件目标目录不存在。如果您确定该文件存在,则缺少uploads/目录。

您可能希望将目录作为绝对路径,以避免不同的脚本找到不同的目录。

答案 1 :(得分:0)

确保为脚本分配了适当的权限,并且文件夹与标题为uploads的脚本位于同一位置。 CHMOD就是你想要的(尽量避免使用777,这只是懒惰)

另外,这是一个Windows主机吗?虽然没关系,但你可以试试这个:

$target_path = "uploads" . DIRECTORY_SEPARATOR; //Declaring Path for uploaded images