0

I had saved files in folder "uploads".I want to display uploaded filename in the table. There are two files. london.jpeg & usa.pdf

Table:

no Name File
1 abc london
2 xyz usa

When one click on london or usa, one should able to see the file.

I need urngent help. I hope i am clear for everyone.

*ERROR: Unknown error type: [8] Undefined index: picture<br /> *
Here is the code:

// dashboard.php
$upload_dir = '/home/www/images/file-upload/upload/'; // Directory for file storing
$upload_dir = $upload_dir . basename($_FILES['picture']['name']);
$filename = $_FILES['picture']['name']; 
$query = "INSERT INTO "

// upload-picture.php
<?php
    $upload_dir = '/home/www/images/file-upload/upload/'; // Directory for file storing
    $preview_url = 'http://www.sitename.com/images/file-upload/upload/'; // 
    $filename= '';

    $result = 'ERROR';
    $result_msg = '';
    $allowed_image = array ('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg','image/png','image/pdf');
    define('PICTURE_SIZE_ALLOWED', 2242880); // bytes

    if (isset($_FILES['picture']))  // file was send from browser
    {
        if ($_FILES['picture']['error'] == UPLOAD_ERR_OK)  // no error
        {
            if (in_array($_FILES['picture']['type'], $allowed_image)) {
            if(filesize($_FILES['picture']['tmp_name']) <= PICTURE_SIZE_ALLOWED) // bytes
            {
                $filename = $_FILES['picture']['name'];
                move_uploaded_file($_FILES['picture']['tmp_name'], $upload_dir.$filename); // pb ici

                //phpclamav clamscan for scanning viruses
                //passthru('clamscan -d /var/lib/clamav --no-summary '.$upload_dir.$filename, $virus_msg); //scan virus
                $virus_msg = 'OK'; //assume clamav returing OK.
                if ($virus_msg != 'OK') 
                {
                    unlink($upload_dir.$filename);
                    $result_msg = $filename." : ".FILE_VIRUS_AFFECTED;
                    $result_msg = '<font color=red>'.$result_msg.'</font>';
                    $filename = '';
                }
                else 
                {
                    // main action -- move uploaded file to $upload_dir
                    $result = 'OK';
                }
            }
    else 
    {
        $filesize = filesize($_FILES['picture']['tmp_name']);// or $_FILES['picture']['size']
        $filetype = $_FILES['picture']['type'];
        $result_msg = PICTURE_SIZE;
    }
    }
    }else {
    $result_msg = SELECT_IMAGE;
    }
    }
    elseif ($_FILES['picture']['error'] == UPLOAD_ERR_INI_SIZE)
    $result_msg = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
    else
    $result_msg = 'Unknown error';

    // This is a PHP code outputing Javascript code.
    echo '<script language="JavaScript" type="text/javascript">'."\n";
    echo 'var parDoc = window.parent.document;';
    if ($result == 'OK') {
    echo 'parDoc.getElementById("picture_error").innerHTML =  "";';
    }
    else {
    echo "parDoc.getElementById('picture_error').innerHTML = '".$result_msg."';";
    }

    if($filename != '') {   
    echo "parDoc.getElementById('img_prev').innerHTML = '<img src=\'$preview_url$filename\' id=\'preview_picture_tag\' name=\'preview_picture_tag\' />';";
    }
    echo "\n".'</script>';
    exit(); // do not go futher
    echo "enter";
?>
4
Contributors
20
Replies
86
Views
4 Years
Discussion Span
Last Post by PriteshP23
Featured Replies
  • When you say "table" are you talking about a database table, or an html table? Read More

  • The PHP works, I tested it and I can upload a file. Echoing back the javascript is not a good practice but I don't see it having anything to do with the PHP error you are seeing. The source of the problem is most likely that the form data is … Read More

0

In BOTH table, i want to display the name of uploaded file.

I do not have any idea regarding the error.

Please let me know if you have any idea to get the result.

0

Do you already have a table setup in your database for the uploads? Is your database connection outside of this script?

Basically all you would need is a sql insert around the point where you have saved moved the file to your uploads folder.

0

ALL is set and done for SQL query.

I need to solve out ONLY Error that i mentioned in earlier post.

0

All the error basically means is that you are calling $_FILES['picture'] but it has not been set yet.
The problem is on line 55.

0

It shows error on line 4. I think there is problem on line 4 and line 26.

0

See first you have this, asking if $_FILES['picture'] exists.

if (isset($_FILES['picture'])){

But then you have this, and you are trying to use it even though it doesn't exist.

elseif ($_FILES['picture']['error'] == UPLOAD_ERR_INI_SIZE)

This may possibly work. Test it out.

elseif ($_FILES['picture'] = '' && $_FILES['picture']['error'] == UPLOAD_ERR_INI_SIZE)
0

I tried it. SAME ERROR it is displaying.

Please le me know where i can change it and get the result.

0

Make sure the link in your form for the file is set to name="picture".

<input type="file" name="picture" id="file">
0

Yes, of course. Here it is:

<table>
    <tr>
    <td>Attachement</td>
    <td>
        <input type="file" name="picture" id="picture" required="required" onchange="ajaxFileUpload(this); return readURL(this);" size="31px"; height="40px"; style="float:left; width:282px; height:30px; "/>   
    </td>
    </tr>
</table>

<div style=" height: 340px; width: 520px;">  
    <img id="img_prev" src="#" style="padding:20px; height: 300px; width: 480px; " />
</div>   
1

Error in below code.Please try not to mix javascipt with php.

   // This is a PHP code outputing Javascript code.
     echo '<script language="JavaScript" type="text/javascript">'."\n";//error
    echo 'var parDoc = window.parent.document;';
     if ($result == 'OK') {
     echo 'parDoc.getElementById("picture_error").innerHTML =  "";';
     }
     else {
     echo "parDoc.getElementById('picture_error').innerHTML = '".$result_msg."';";
     }
     if($filename != '') {   
     echo "parDoc.getElementById('img_prev').innerHTML = '<img src=\'$preview_url$filename\' id=\'preview_picture_tag\' name=\'preview_picture_tag\' />';";
     }
echo "\n".'</script>';

Instead of using javascript inside php,make an ajax call to this php page and upload file and then return filename as response of ajax call.Then set the file name using response of ajax call.

0

If possible, Please provide by example that you had told. I am not good at AJAX. Thanks a lot in advanced.

2

The PHP works, I tested it and I can upload a file. Echoing back the javascript is not a good practice but I don't see it having anything to do with the PHP error you are seeing. The source of the problem is most likely that the form data is not being passed of to the PHP script properly which is why it is complaining about $_FILE['picture']. I can get the same error if I just go directly to upload.php rather than submitting data to it.

If you are trying to make this all asynchronous I would recommend looking at something like jQuery or Mootools which can help make the whole ajax part a lot easier. A lot of people have built plugins for that sort of thing, so you can utilize those.

0

Can anyone correct my code ? Or I would like to have a Simple example.

Edited by PriteshP23: code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.