Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:11:35+00:00 2026-06-13T12:11:35+00:00

I’ve been creating a HTML5 Drag & Drop image up-loader. All is good with

  • 0

I’ve been creating a HTML5 Drag & Drop image up-loader. All is good with the Javascript side of things however the PHP is driving me crazy!

I’ve been able to create a script that successfully places a image in a folder upon the drop of an image, however once it tries to create a thumb nail for the image and place the image link into the users db table it all goes to pot. I’ve sat here for hours on end, trying and trying to no avail, so i believe as it is now just about 3am GMT i should admit defeat and ask for a little help.

The JavaScript:

$(function(){

var dropbox = $('#dropbox'),
    message = $('.message', dropbox);

dropbox.filedrop({
    paramname:'pic',

    maxfiles: 5,
    maxfilesize: 200,
    url: 'uploadCore.php',

    uploadFinished:function(i,file,response){
        $.data(file).addClass('done');
    },

    error: function(err, file) {
        switch(err) {
            case 'BrowserNotSupported':
                showMessage('Your browser does not support HTML5 file uploads!');
                break;
            case 'TooManyFiles':
                alert('Too many files!');
                break;
            case 'FileTooLarge':
                alert(file.name+' is too large! Please upload files up to 200mb.');
                break;
            default:
                break;
        }
    },

    beforeEach: function(file){
        if(!file.type.match(/^image\//)){
            alert('Only images are allowed!');

            return false;
        }
    },

    uploadStarted:function(i, file, len){
        createImage(file);
    },

    progressUpdated: function(i, file, progress) {
        $.data(file).find('.progress').width(progress);
    }

});

var template = '<div class="preview">'+
                    '<span class="imageHolder">'+
                        '<img />'+
                        '<span class="uploaded"></span>'+
                    '</span>'+
                    '<div class="progressHolder">'+
                        '<div class="progress"></div>'+
                    '</div>'+
                '</div>'; 


function createImage(file){

    var preview = $(template), 
        image = $('img', preview);

    var reader = new FileReader();

    image.width = 100;
    image.height = 100;

    reader.onload = function(e){            
        image.attr('src',e.target.result);
    };

    reader.readAsDataURL(file);

    message.hide();
    preview.appendTo(dropbox);

    $.data(file,preview);
}

function showMessage(msg){
    message.html(msg);
}

});

Now for the PHP:

<?php

// db connection
 include("db-info.php");
    $link = mysql_connect($server, $user, $pass);
        if(!mysql_select_db($database)) die(mysql_error());

 include("loadsettings.inc.php");


//$upload_dir = 'pictures/';
$allowed_ext = array('jpg','jpeg','png','gif');

if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
    exit_status('Error! Wrong HTTP method!');
}


if(array_key_exists('pic',$_FILES) && $_FILES['pic']['error'] == 0 ){

if (isset($_SESSION["imagehost-user"]))
   { 
      $session = true;
      $username = $_SESSION["imagehost-user"];
      $password = $_SESSION["imagehost-pass"];

      $q = "SELECT id FROM `members` WHERE (username = '$username') and (password = '$password')";
      if(!($result_set = mysql_query($q))) die(mysql_error());
      $number = mysql_num_rows($result_set);

      if (!$number) {
         session_destroy();
         $session = false;
      }else {
         $row = mysql_fetch_row($result_set); 
         $loggedId = $row[0];
    }
}


    $date = date("d-m-y");
    $lastaccess = date("y-m-d");
    $ip = $_SERVER['REMOTE_ADDR'];
    $type = "public";

    $pic = $_FILES['pic'];
        $n = $pic;
            $rndName = md5($n . date("d-m-y") . time()) . "." . get_extension($pic['name']);
                $upload_dir = "pictures/" . $rndName;
                    move_uploaded_file($pic['tmp_name'], $upload_dir.$pic['name']);

                    // issues starts here

                     $imagePath = $upload_dir;

                     $img = imagecreatefromunknown($imagePath);
                        $mainWidth = imagesx($img);
                        $mainHeight = imagesy($img);

                        $a = ($mainWidth >= $mainHeight) ? $mainWidth : $mainHeight; 

                         $div = $a / 150;
                         $thumbWidth = intval($mainWidth / $div);
                         $thumbHeight = intval($mainHeight / $div);

                            $myThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
                             imagecopyresampled($myThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight);
                             $thumbPath = "thumbnails/" . basename($imagePath);
                             imagejpeg($myThumb, $thumbPath);

                             $details = intval(filesize($imagePath) / 1024) . " kb (" . $mainWidth . " x " . $mainHeight . ")" ; 
                             $id = md5($thumbPath . date("d-m-y") . time());


                             $q = "INSERT INTO `images`(id, userid, image, thumb, tags, details, date, access, type, ip)
                             VALUES('$id', '$loggedId', '$imagePath', '$thumbPath', '$tags', '$details', '$date', '$lastaccess', 'member-{$type}', '$ip')";
                                 if(!($result_set = mysql_query($q))) die(mysql_error());*/

                                    exit_status('File was uploaded successfuly!');

                            // to here


    $result = mysql_query("SELECT id FROM `blockedip` WHERE ip = '$ip'");
    $number = mysql_num_rows($result);
        if ($number) die(""); // blocked IP message

    function imagecreatefromunknown($path) {

        $exten = get_extension($path);

       switch ($exten) {
          case "jpg":
            $img = imagecreatefromjpeg($path);
            break;
          case "gif":
            $img = imagecreatefromgif($path);
            break;
          case "png":
            $img = imagecreatefrompng($path);
            break;
  }

  return $img;
}


}

exit_status('Something went wrong with your upload!');

// Helper functions

function exit_status($str){
    echo json_encode(array('status'=>$str));
    exit;
}

function get_extension($file_name){
    $ext = explode('.', $file_name);
    $ext = array_pop($ext);
    return strtolower($ext);
}   

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:11:36+00:00Added an answer on June 13, 2026 at 12:11 pm

    It seems you pass wrong path to the imagecreatefromunknown() function. You pass $imagePath that equals $upload_dir, but your image destination is $upload_dir.$pic['name']

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.