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

    Join Date
    Sep 2012
    Rep Power

    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 />';

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



    the other part of the code is :

    <title> title.</title>
    <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>

    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
    Rep Power
    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