Nov 22, 2009

Upload Button In Php

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Designing > Web Design and HTML

Upload Button In Php

kxrain
Here are some script on upload button in php.
I found this one on the searching for upload button
-------------------------------------------------------
CODE
<?
if(isset($_POST['uploadfile'])){
  $picname = ($_FILES['upfile']['name']);
  move_uploaded_file($_FILES['upfile']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/pictures/" . $_FILES['upfile']['name']);
echo("Your picture has been uploaded<br><br>");
}
echo("<form enctype=\"multipart/form-data\" action=/submitapic.php method=post><input type=hidden name=uploadfile value=1>Picture To Upload<br><input type=file name=upfile>");
echo("<br><br>");
echo("<input type=submit value=\"Upload\"></form>");
?>


A couple notes:
1) make a directory called pictures to upload the pics or files too.
2) if you use a unix based server, you must chmod that directory to either 777 or 755, I don't remember.
3) The script/page is called submitapic.php
4) You can use notepad to make the page, then click file as, choose all files, and name it submitapic.php
5) The file should be placed in the html directory, not the same directory as pictures.

That's it, hope it helps.

 

 

 


Comment/Reply (w/o sign-up)

wutske
One small detail, you have to include this php file in another file or you have to add the <html>, <body, etc ... tags.

I've once written a more complicated uploadscript that would create and chmod the directories if needed (sorry for the dutch comments and variables)
CODE
<?php
require_once('session_check.php');
$titel = 'Upload een afbeelding';
$stylesheet = '"../style.css"';
include_once('../html_head.inc');
require_once('resize_image_function.php');
require('SQL_connect.php');
require('SQL_read.php');

$album_folder = read_SQL(album_folder, album);
$folder = $_POST['folder'];

$thumbnail_maximum_heigth = read_SQL(thumbnail_maximum_heigth, thumbnails);        //nieuwe maximale hoogte
$thumbnail_maximum_width = read_SQL(thumbnail_maximum_width, thumbnails);        //nieuwe maximale breedte
$thumbnail_herschaal = read_SQL(thumbnail_herschaal, thumbnails);    //herschaalmodus
$thumbnail_jpeg_kwaliteit = read_SQL(thumbnail_jpeg_kwaliteit, thumbnails); //JPEG kwaliteit van thumbnail    

$upload_max_size = read_SQL(upload_max_size, upload);
$upload_maximum_heigth = read_SQL(upload_max_height, upload);        //nieuwe maximale hoogte
$upload_maximum_width = read_SQL(upload_max_width, upload);        //nieuwe maximale breedte
$upload_jpeg_kwaliteit = read_SQL(upload_jpeg_kwaliteit, upload); //JPEG kwaliteit van upload    

$uploadmap = '/home/wutske/public_html/PHP/' . $album_folder . '/' . $folder;
$tijdelijk_bestand = $_FILES['afbeelding1']['tmp_name'];
$bestandsnaam = $_FILES['afbeelding1']['name'];

if (isset($_POST['afbeelding_submit']))
{
    if (!file_exists($uploadmap))
    {
        if (is_writable('/home/wutske/public_html/PHP/' . $album_folder))
        {
            if (mkdir($uploadmap))
            {
                echo $uploadmap . ' aangemaakt <br />';
                if (chmod($uploadmap, 0777));
                    echo 'Rechten gewijzigd naar 0777<br />';
            }
            else
            {
            die('Aanmaken uploadmap gefaald !');
            }
        }
        else
            die('De hoofd-albummap is niet beschrijfbaar, gelieve deze te chmodden');
    }
    
    if (is_writable($uploadmap))
    {
        //controleert bestandsgrootte
        if ($_FILES['afbeelding1']['size'] > $upload_max_size)
            {
                //verwijderen tijdelijk bestand indien te groot
                if (unlink($_FILES['afbeelding1']['tmp_name']))    
                    echo '<div class="warning">Tijdelijk bestand verwijderd, reden: ';
                    //echo indien tijdelijk bestand verwijderd. Altijd die indien te groot bestand.
                    die('Bestand is te groot, de maximale grootte is ' . $upload_max_size . '. Bestandgroote = ' . $_FILES['afbeelding1']['size'] . '</div>');
            }
        else
            {
                //aanmaken thumbnail:
                if ( !file_exists($uploadmap . '/thumbnails'))
                        {
                            echo '<div class="info">De thumbnail folder bestaat nog niet, deze wordt aagemaakt</div>';
                            if (!is_writable($uploadmap))
                            {
                                echo '<div class="info">De album folder is niet beschrijfbaar, er wordt geprobeert deze beschrijfbaar te maken: </div>';
                                /*if (chmod($set_map, 0777))
                                    echo '<div class="info">De thumbnail folder is nu beschrijfbaar</div>';
                                else
                                    echo '<div class="error">Kon de thumbnail folder niet beschrijfbaar maken ... u krijg waarschijnlijk een hele resem errors ...<br />
                                    Gelieve de folder schrijfbaar te maken via bv. FTP</div>';
                                */
                            }
                            else
                            {
                                mkdir($uploadmap . '/thumbnails', 0777);
                                chmod($uploadmap . '/thumbnails', 0777);
                            }
                        }
                    else
                        {
                            if (!is_writable($uploadmap . '/thumbnails'))
                            {
                                echo '<div class="info">De thumbnail folder is niet beschrijfbaar, er wordt geprobeert deze beschrijfbaar te maken: </div>';
                                if (chmod($thumbnail_folder, 0777))
                                {
                                    echo '<div class="info">De thumbnail folder is nu beschrijfbaar</div>';
                                }
                                else
                                {
                                    echo '<div class="error">Kon de thumbnail folder niet beschrijfbaar maken ... u krijg waarschijnlijk een hele resem errors ...<br />
                                    Gelieve de folder schrijfbaar te maken via bv. FTP</div>';
                                }
                                //chown($thumbnail_folder, 32106);
                            }
                        }    
                    resize_image('', $tijdelijk_bestand, 'tn_', $_FILES['afbeelding1']['name'], $uploadmap, '/thumbnails', $thumbnail_maximum_width, $thumbnail_maximum_heigth, $thumbnail_herschaal, $thumbnail_jpeg_kwaliteit);    
                
                
                if ($_POST['resize'] !== 'y')
                {
                //indien er een fout is opgetreden bij het verplaatsten van het tijdelijk bestand
                if (!(move_uploaded_file($_FILES['afbeelding1']['tmp_name'], $uploadmap . '/' . $bestandsnaam)))
                    {
                        //Bij fout, tijdelijk bestand verwijderen, indien verwijderd, eerste die, indien niet, die fatal error).
                        if (unlink($_FILES['afbeelding1']['tmp_name']))
                            die('<div class="warning">Er is een fout opgetreden ... het tijdelijk bestand is verwijderd.</div>');
                        else
                            die('<div class="warning">Fatal error: Upload niet succesvol en tijdelijk bestand niet verwijderd</div>');
                    }
                else
                    {
                    echo 'Bestand succesvol geuploaded naar: ' . $uploadmap . '/' . $bestandsnaam;
                    }
                }
                else
                {
                //Herschalen van het geuploaded bestand
                resize_image('', $tijdelijk_bestand, '', $_FILES['afbeelding1']['name'], $uploadmap, '', $upload_maximum_width, $upload_maximum_heigth, 2, $upload_jpeg_kwaliteit);
                }
                

            }
    }
    else
        die('<div class="warning">Kan niet schrijven in de map ' . $uploadmap . '</div>');
}

else
{
    echo 'Uploaden naar: ' . $uploadmap;
    echo '<br />De Maximale grootte is ' . ( $upload_max_size / 1024 ) . ' KB';
?>


<form enctype="multipart/form-data" action="upload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="
    <?php
        echo upload_max_size
    ?>
    " />
    <!-- Name of input element determines name in $_FILES array -->
    <table>
        <tr>
            <td width ="100px">
                Bestand 1:
            </td>
            <td>
                <input name="afbeelding1" type="file" size="100" /><br />
            </td>
        </tr>
        <tr>
            <td width="100px">
                Map
            </td>
            <td>
                <input type="textbox" name="folder" />
            </td>
        </tr>
        <tr>
            <td width="100px">
                Herschaal ?
            </td>
            <td>
                <input type="checkbox" name="resize" value="y" checked="cheched"/>
            </td>
        </tr>
    </table>
    <input type="submit" name="afbeelding_submit" value="Send File" />
</form>

<?php
}
?>

 

 

 


Comment/Reply (w/o sign-up)

kxrain
That was very complicated. I am new in php so im beginning to create simple things. The complicated one i think im gotta do it soon..lol.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for upload, button, php
advertisement



Upload Button In Php

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com