#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Very simple upload image script


    Hello everyone. I am trying to create a very simple script that could get images to the database with its name, extension and a specific size. I want to display pictures later on my website that would have the same resolution and size. The pictures would go to the same folder. I now have a part of the code (still building it) that for some reasons shows me blank. COuld you help me out please, i am very new to php and need your help. [ /PHP]

    Here is that code:


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

    $image_name = $_FILES['file_upload'] ['name'] ;
    $image_size = $_FILES ['file_upload'] ['size'];
    $image_temp = $_FILES ['file_upload'] ['tmp_name'];

    $allowed_ext = array('jpeg','jpg','png','gif');
    $image_ext = strtolower(end(explode('.', $image_name)));

    $errors = array();


    if(empty($image_name)) {
    $errors [] = 'Something is missing';
    }else {

    if(in_array($image_ext, $allowed_ext) === false) {
    $errors [] = 'File type isn\'t allowed';
    }

    if($image_size > 2097152) {
    $errors [] = 'Maximum size is 2 mb';
    }
    }


    if(!empty($errors)) {
    foreach($errors as $error) {
    echo $error, '<br />';
    }
    }else{

    $uploadfile = dirname (__FILE__) . '/' . basename($_FILES['file_upload']['name']);
    Copy($_FILES['file_upload']['tmp_name'], $uploadfile);

    }
    }


    ?>


    the other part of the code is :

    <html>
    <head>
    <title> title.</title>
    </head>
    <body>
    <form action="receive.php" id="upload_form" method="post" enctype="multipart/form-data" target="upload_target">
    <input type="file" name="file_upload" />
    <input type="submit" value="Download" />
    <div id="result"></div>
    <iframe id="upload_target" name="upload_target" style="display: none;"></iframe>
    </form>
    </body>
    </html>

    Sorry, tell me how to use php tegs please? i want my code to be written in a proper way next time. thanks
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,547
    Rep Power
    2337
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!

IMN logo majestic logo threadwatch logo seochat tools logo