Results 1 to 2 of 2

Thread: Uploading Issue

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Uploading Issue

    Hello, I am attempting to make a script that will upload a preview image and a file and insert the data into a SQL database, but for some reason, my script is not reading what is put in my file fields. Here is my code:
    PHP Code:
    <?php
    ########## If add download was hit ##########
    else if ($_GET['act'] == 'downloads') {
        
        
    // If form sent
        
    if ($_POST['add']) {
            
    $title mysql_real_escape_string($_POST['title']);
            
    $description mysql_real_escape_string($_POST['description']);
            
    $date date('n/j/y');
            
    $imgUploadPath $path.basename(''.$title.'_'.$_FILES['img']['name'].'');
            
    $fileUploadPath $filePath.basename("".$_FILES['files']['name']."");
            
            
    // Check fields
            
    if (!$title || !$date) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Please fill in all fields.</span>'; } 
            
            
    // Move file
            
    else if (!move_uploaded_file($_FILES['img']['tmp_name'], $imgUploadPath)) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Error uploading the preview image</span>'; echo $path.basename(''.$title.'_'.$_FILES['img']['name'].'');} 
            
            else if (!
    move_uploaded_file($_FILES['files']['tmp_name'], fileUploadPath)) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Error uploading the file</span>'; } 
            
            else {
            
    $insert mysql_query("INSERT INTO `downloads` (id, title, description, url, img, date) VALUES ('', '$title', '$description', '$filePath".$_FILES['name']['files']."', '$path".$title."_".$_FILES['name']['img']."', '$date')") or die ("Error Inserting Download! \n<br />\n" .mysql_error());
            
            echo 
    '<meta http-equiv="refresh" content="2;URL=index.php" /> The download, <b>'.$title.'</b> has been added.';
            }
        }
        
        
        
    // If form not sent
        
    if (!$_POST['add']) { ?>
        
                <!-- Add Download Form -->
                <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>?act=downloads" title="add_news">
                    <table width="400" align="center">
                        <tr>
                            <td width="72">Title:</td>
                            <td width="316"><input type="text" name="title" /></td>
                        </tr>
                        <tr>
                            <td>Description:</td>
                            <td><input name="description" type="text" maxlength="200" /></td>
                        </tr>
                        <tr>
                            <td>Image:</td>
                            <td><input type="file" name="img" /></td>
                        </tr>
                        <tr>
                            <td>File:</td>
                            <td><input type="file" name="files" /></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input type="submit" name="add" value="Add" /></td>
                        </tr>
                    </table>
                </form>
            <!-- /Add Download Form -->
            
        <? }
    }
    ?>
    I tested it by echoing "$_FILES['img']['name']" and it returned nothing. Any Ideas about what is wrong? Thanks
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nevermind, I found the problem, I forgot the enctype="multipart/form-data" : / darn simple mistakes
    Thanks DD, you saved me countless times

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •