Web Analytics Made Easy -
StatCounter Wierd Error MSG??? - CodingForum

Announcement

Collapse
No announcement yet.

Wierd Error MSG???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wierd Error MSG???

    I'm trying to get my script to upload multiple files, and the files will be in mp3, gif, jpg, png, mpg, mpeg, and mov.

    the script runs fine when I'm uploading a file other than a video, but fails with this message when I'm uploading a movie:

    Warning: move_uploaded_file(/home/spanishm/public_html/ccm/spanishm/videos/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/spanishm/public_html/php/authpal/members/ccmadmin.php on line 1346

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phplE28P6' to '/home/spanishm/public_html/ccm/spanishm/videos/' in /home/spanishm/public_html/php/authpal/members/ccmadmin.php on line 1346
    here is the code that I have used. the first function is the html page used to upload files, and the second function is the one used to actually upload the files... Line 1346 is highlighted in red.

    PHP Code:
    function addcontent(){
    ?>

    <html>
            <head>
                <title>Welcome to Spanishmania.ca - Your Spanish Connection</title>
        
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
                <meta http-equiv="Pragma" content="no-cache" />
                <meta http-equiv="Expires" content="0" />
                <link rel="SHORTCUT ICON" href="http://www.spanishmania.ca/favicon.ico" />
              <link rel="stylesheet" type="text/css" href="http://www.spanishmania.ca/css/content.css" />
                <link rel="stylesheet" type="text/css" media="screen" href="upload-progress.css" />
                <script src="upload-progress.js" type="text/javascript"></script>
        
                <style type="text/css">
        <!--
        .style1 {font-size: large}
        .style2 {
            color: #FF0000;
        }
        -->
                </style>
        
        <SCRIPT LANGUAGE="JavaScript">
        <!-- Original: wsabstract.com -->
        
        <!-- This script and many more are available free online at -->
        <!-- The JavaScript Source!! http://javascript.internet.com -->
        
        <!-- Begin
        function checkrequired(which) {
        var pass=true;
        if (document.images) {
        for (i=0;i<which.length;i++) {
        var tempobj=which.elements[i];
        if (tempobj.id.substring(0,8)=="required") {
        if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&
        tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
        tempobj.selectedIndex==0)) {
        pass=false;
        break;
                         }
                    }
             }
        }
        if (!pass) {
        alert("You must upload at least 1 File, and each\n\nupload must have a title and description.");
        return false;
        }
        else
        return true;
        }
        //  End -->
        </script>
        
        </head>
    <body>
            <div name="top" align="center" id="header">
                    <br />
                Course Content<br />
    <span class="style1">Contenido del curso</span></div>
                <br />
        <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                        <p align="center" class="style1">Delete Course </p>
                        
                        <?php
                        
    if ($_SESSION['file_uploaded'] != ""){
                        
                          echo 
    "<p align=\"center\" class=\"style2\">" $_SESSION['file_uploaded'] . "</p>";
                            
                            
    $_SESSION['file_uploaded'] = "";
                        
                        }
                         
                        if (
    $_SESSION['uploaderror'] == "true"){
                          
                            foreach (
    $_SESSION['upload_errors'] as $key => $value){
                        
                            echo 
    "<p align=\"center\" class=\"style2\">" $value "</p>";
                        
                          }
                            
                            
    $_SESSION['uploaderror'] = "";
                            
                        }
                        
    ?>
                        <p align="center">To delete an existing course, please select the course name from the drop down menu below, then click 'Submit'.</p>
        <div id="upload">
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=addcontentsubmit" method="post" enctype="multipart/form-data" id="uploadform" onSubmit="return checkrequired(this)">
        <input type="hidden" name="MAX_FILE_SIZE" value="26214400" />
            <p>Select the course you wish to add media to: 
                <select name="course" accesskey="c" tabindex="1">
            <?php
            
            
    if ($handle opendir($_SESSION['base_dir'])) {  
                    
                while (
    false !== ($file readdir($handle))) {
                    
                if (
    $file != "." && $file != ".."){
                
                    echo 
    "<option value=\"" $file "\">" $file "</option>\n";
                
                }
                
             }
            
            }
            
    ?>
                </select>
            </p>
            <p>You may add up to 5 media files at a time as not to overload the server. Your total upload should be no more than 25MB.<br>
          <br>To Check the file size of any of the files that your uploading, please right click on the file and select '<strong>Properties</strong>' from the dropdown.
                <br><br>Your total upload must not be more than 25MB to calculate this, you might need the size measurements, and they are as follows:
                <br><br>1 byte - the smallest measurement<br>
                1 <strong>kb</strong> (kilo-byte) - is equal to 1024 <strong>bytes</strong><br>
                1 <strong>MB</strong> (mega-byte) - is equal to 1024 <strong>kb</strong><br><br>
                These are the 3 measurement units that you will need to know in order to calculate the total upload size. For example if you need to convert a filesize of 1274306 bytes into kb, just devide by 1024 every time you increase the unit size (bytes -> kb -> MB)<br><br>
                example: (1274306 bytes &divide; 1024 = 1244.439453125 kb then &divide; 1024 = 1.2152729034423828125 MB so in essence our file is 1.22 MB rounded to the nearest ten.<br><br>
                If you need to convert per say the total allowed upload size of 25 MB, the process would be much the same, however, instead of dividing by, you would multiply by 1024<br><br>
                example: 25 MB x 1024 = 25600 kb x 1024 = 262144000 bytes.<br><br>
                Use this as a guide to to determining file size to avoid waiting for the file to upload only to find out that your upload was too big and that you now have to resend everything. As long as your total upload does not exceed 25 MB.
          <br />
                <br />
                Just click on the browse button next to the text input field to browse to the file that you wish upload from your computer and click ok you should then see the path to this file appear in the text field beside the browse button.</p>
            <p>First File: </p>
            <p>            </p>
            <input name="media[]" type="file" id="requiredmedia[]" tabindex="2" />
            </p>
            <p>Enter a title for the media file: 
                <input name="title0" type="text" id="requiredtitle0" tabindex="3" />
            </p>
            <p>Enter a description for the media file:</p>
            <p>
                <textarea name="description0" cols="40" rows="4" id="requireddescription0" tabindex="4"></textarea>
        </p>
            <p>Second File: </p>
            <p>
                <input name="media[]" type="file" id="media[]" tabindex="5" />
            </p>
            <p>Enter a title for the media file:
                <input name="title1" type="text" id="title1" tabindex="6" />
            </p>
            <p>Enter a description for the media file:</p>
            <p>
                <textarea name="description1" cols="40" rows="4" id="description1" tabindex="7"></textarea>
            </p>
            <p>Third File: </p>
            <p>
                <input name="media[]" type="file" id="media[]" tabindex="8" />
            </p>
            <p>Enter a title for the media file:
                <input name="title2" type="text" id="title3" tabindex="9" />
            </p>
            <p>Enter a description for the media file:</p>
            <p>
                <textarea name="description2" cols="40" rows="4" id="description3" tabindex="10"></textarea>
            </p>
            <p>Fourth File: </p>
            <p>
                <input name="media[]" type="file" id="media[]" tabindex="11" />
            </p>
            <p>Enter a title for the media file:
                <input name="title3" type="text" id="title4" tabindex="12" />
            </p>
            <p>Enter a description for the media file:</p>
            <p>
                <textarea name="description3" cols="40" rows="4" id="description4" tabindex="13"></textarea>
            </p>
            <p>Fifth File: </p>
            <p>
                <input name="media[]" type="file" id="media[]" tabindex="14" />
            </p>
            <p>Enter a title for the media file:
                <input name="title4" type="text" id="title5" tabindex="15" />
            </p>
            <p>Enter a description for the media file:</p>
            <p>
                <textarea name="description4" cols="40" rows="4" id="description5" tabindex="16"></textarea>
            </p>
            <p>
                <input type="submit" name="Submit" value="Submit" accesskey="s" tabindex="17" />
        </p>
        </form>
        </div>
        <p align="center">&nbsp;</p></td>
                </tr>
        </table>
        </body>
            <head>
                <meta http-equiv="PRAGMA" content="NO-CACHE" />
            </head>
    </html>
    <?php
    }

    function 
    addcontentsubmit(){

    $Save_Post_Files $_FILES;

      
    $_SESSION['upload_errors'] = array();    
        
        if (
    $_FILES['media']['name'][0] == ""){
        
          
    array_push($_SESSION['upload_errors'], "You must pick at least 1 file to upload<br>\n");
            
    $ok=0;
        
        }
        
        
    $countmedia 0;
        
        foreach (
    $_FILES['media']['name'] as $key => $value){
        
          if (
    $_FILES['media']['name'][$key] != ""){
            
              
    $countmedia++;
            
            }
        
        }
        
        
    $course $_POST['course'];
        
        unset(
    $i);
        
    $i=0;
        
        while (
    $i <= ($countmedia 1)){
            
            
    $mediatype $Save_Post_Files['media']['type'][$i];
            
    $title "title" $i;
            
    $description "description" $i;
            
            if (
    $mediatype == "video/mpg" || $mediatype == "video/mpeg" || $mediatype == "video/mov" || $mediatype == "video/quicktime"){
            
              
    $target "/home/spanishm/public_html/ccm/" $course "/videos/";
              $
    $target $target basename$Save_Post_Files['media']['name'][$i]);
              
    $ok=1;
                
            }
            
            if (
    $mediatype == "application/doc" || $mediatype == "application/msword" || $mediatype == "application/pdf"){
            
              
    $target "/home/spanishm/public_html/ccm/" $course "/docs/";
              
    $target $target basename$Save_Post_Files['media']['name'][$i]);
              
    $ok=1;
                
            }
            
            if (
    $mediatype == "image/jpg" || $mediatype == "image/jpeg" || $mediatype == "image/gif" || $mediatype == "image/png"){
            
              
    $target "/home/spanishm/public_html/ccm/" $course "/pics/";
              
    $target $target basename$Save_Post_Files['media']['name'][$i]);
              
    $ok=1;
                
            }
            
            
    //This is our size condition
            
    if ($Save_Post_Files['media']['size'][$i] >= 26214401){
            
                
    array_push($_SESSION['upload_errors'], "Your file is too large.");
                
    $ok=0;
            
            }
            
            
    //This is our limit file type condition
            
    if ($mediatype != "video/mpeg" && $mediatype != "video/mpg" && $mediatype != "video/mov" && $mediatype != "video/quicktime" && $mediatype != "application/doc" && $mediatype != "application/msword" && $mediatype != "application/pdf" && $mediatype != "image/jpg" && $mediatype != "image/jpeg" && $mediatype != "image/gif" && $mediatype != "image/png"){
            
                
    $fterror "You may only upload files that have the extention of: .mpg, .mpeg, .mov, .doc, .pdf, .jpg, .jpeg, .gif and .png";
                
                echo 
    print_r($Save_Post_Files);
                echo 
    "\n<br><br>\n";
                echo 
    $Save_Post_Files['media']['type'][$i];
                echo 
    "\n<br><br>\n";
                echo 
    $mediatype;
                echo 
    "\n<br><br>\n";
                echo 
    "\$i: " $i;
                
                
    array_push($_SESSION['upload_errors'], $fterror);
                
    $ok=0;
            
            }
            
            
    $i++;
            
        }

            
    //Here we check that $ok was not set to 0 by an error
            
    if ($ok == 0){
            
                
    $_SESSION['uploaderror'] = "true";
                
                
    //print_r($_SESSION['upload_errors']);
                
                
    addcontent();
                exit;

            
            }
            
        
    $i=0;
            
        while (
    $i <= ($countmedia-1)){
                
          
    //If everything is ok we try to upload it
    LINE 1346 -> if(move_uploaded_file($Save_Post_Files['media']['tmp_name'][$i], $target)){
    PHP Code:
                $print_title "title" $i;
                
    $print_description "description" $i;
                
                
    $myFile $target ".txt";
                
    $fh fopen($myFile'w') or die("can't open file");
                
    $stringData $_POST[$print_title] . "|||" $_POST[$print_description];
                
    fwrite($fh$stringData);
                
    fclose($fh);
                
                
    $_SESSION['upload_success'][] = "The file '" basename($Save_Post_Files['media']['name'][$i]) . "' has been uploaded to '" $course "'";
                
                
    $_SESSION['upload_success_switch'] = "true";
                 
            }
            else{
            
                
    $_SESSION['upload_success'][] = "Sorry, there was a problem uploading your file '" $Save_Post_Files['media']['name'][$i] . "' to '" $target "'";
            
            }
            
            
    $i++;
            
      }
        
      
    main();
        exit;


    I have searched on the internet everywhere for mention of this 'Failed to open stream: Is a Directory in' error and can't find anything at all... what on earth does this mean???

    Can anyone help me please,
    Titanic_Fanatic
    Last edited by titanic_fanatic; Oct 2, 2006, 05:06 PM. Reason: line 1346 wasn't highlighted

  • #2
    http://ca.php.net/move_uploaded_file

    If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

    If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.
    Soo there is a problem with the move... have your returned the temp name and the 'new path' to be sure both of them are correct?

    can you hard code in these values for a test?
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

    Comment


    • #3
      wow... I feel really stupid... the target variable was being set based on the ext of the file to determine type and upload to either /videos, /pics or /docs and the target variable was set like this $$target instead of $target and therefore not being able to find the file.

      Thank you for making me look at the simple possibility... I probably would have looked it over a thousand more time...

      Comment


      • #4
        Originally posted by titanic_fanatic View Post
        wow... I feel really stupid... the target variable was being set based on the ext of the file to determine type and upload to either /videos, /pics or /docs and the target variable was set like this $$target instead of $target and therefore not being able to find the file.

        Thank you for making me look at the simple possibility... I probably would have looked it over a thousand more time...
        not a problem.. sometimes it's the simple things...

        good luck too ya!
        public string ConjunctionJunction(string words, string phrases, string clauses)
        {
        return (String)(words + phrases + clauses);
        }
        <--- Was I Helpfull? Let me know ---<

        Comment

        Working...
        X