HELP: php code Not executed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HELP: php code Not executed

    Need help on this code, the stream_copy_to_stream function is properly executing because I see the file in folder but in inserting data in mySql is not executing.
    PHP Code:
    <?php
    include 'head.php';
    include 
    'db.php';
    session_start();
    if(isset(
    $_SESSION['uid']))
    {
    $user=$_SESSION['uid'];
    $sql mysql_query("SELECT * FROM users WHERE userid='$user'");
    $row mysql_fetch_array($sql);
    $user=$row[5];
    }else{
    $user="Guest";
    }
    $ssname=$_FILES["screenshot"]["name"];
    $category=$_POST['category'];
    $name=$_POST['name'];
    $description=$_POST['description'];
    $tdate=date("d/m/y");
    if(empty(
    $_POST['file'])) {
            echo 
    "<font color='red'>File name is empty!</font><hr>";
    }
    /*
    $validlist = array("apk", "avi", "mid", "gif", "bmp", "midi", "3gp", "mp4", "avi", "mp3", "m4a", "aac", "wav", "mpn", "nth", "mpc", "jar", "jpeg", "jpg", "sis", "sisx", "mmf", "amr", "thm", "png", "wbmp);
    foreach ($validlist as $type) {
        if(!preg_match("/$type\$/i", $name)) {
            echo "<font color='red'>Failed to upload file. Make sure the file extension in file name are valid extension!</font><hr>\n";
    include("upload.php");
    include("foot.php");
            exit;
        }
        }
    */
    $blacklist = array(".php"".phtml"".php3"".php4"".php5"".php6"".cgi"".fcgi"".htaccess"".js"".shtml"".pl"".py"".exe"".bat"".sh");
    foreach (
    $blacklist as $type) {
        if(
    preg_match("/$type\$/i"$name)) {
            echo 
    "<font color='red'>We do not allow uploading files that block in our list</font><hr>\n";
    include(
    "upload.php");
    include(
    "foot.php");
            exit;
        }
        }
    if (
    file_exists("files/$category/" $name))
          {
          echo 
    "<font color='red'>" $name " already exists please try another or change the file name</font><hr>";
    }
        else
          {
    $file $_POST["file"];
    if(!
    stream_copy_to_stream(fopen($file"r"), fopen("files/".$category."/"$name"w+")))
    {
            echo 
    "<font color='red'>Failed to upload file. Make sure the URL is correct!</font><hr>";
    include(
    "upload.php");
    include(
    "foot.php");
            exit;
    }else{
    stream_copy_to_stream(fopen($file"r"), fopen("files/".$category."/"$name"w+"));
    }
    $type=filetype("files/".$category."/"$name);
    $size=(filesize("files/".$category."/"$name)/1024);
    $url2="files/".$category."/"$name;
    $url3="files/".$category."-Thumb/"$name;
    if (
    $category=='Applications' || $category=='Games' || $category=='Videos' || $category=='Themes' || $category=='Other' || $category=='E-Books' || $category=='Scripts')
    {
    if (isset(
    $ssname)){
    $thumb="files/Screenshots/" $ssname;
    }else{
    $thumb='images/application.gif';
    }
    }
    elseif (
    $category=='Ringtones' || $category=='Music')
    {
    if (isset(
    $ssname)){
    $thumb="files/Screenshots/" $ssname;
    }else{
    $thumb='images/sound.gif';
    }
    }
    elseif (
    $category=='Wallpapers' || $category=='Screensavers' || $category=='Pictures18')
    {
    //start thumbnail
    function thumbnail_image($original_file_path$new_width$new_height$save_path="",$name2)
    {
        
    $imgInfo getimagesize($original_file_path);
        
    $imgExtension "";

        switch (
    $imgInfo[2])
        {
            case 
    1:
                
    $imgExtension '.gif';
                   break;

            case 
    2:
                
    $imgExtension '.jpg';
                break;

            case 
    3:
                
    $imgExtension '.png';
                break;
        }
        
        if (
    $save_path==""$save_path "files/Pictures-Thumb/".$name2.$imgExtension ;

        
    // Get new dimensions
        
    list($width$height) = getimagesize($original_file_path);

        
    // Resample
        
    $imageResample imagecreatetruecolor($new_width$new_height);

        if ( 
    $imgExtension == ".jpg" )
        {
            
    $image imagecreatefromjpeg($original_file_path);
        }
        else if ( 
    $imgExtension == ".gif" )
        {
            
    $image imagecreatefromgif($original_file_path);
        }
        else if ( 
    $imgExtension == ".png" )
        {
            
    $image imagecreatefrompng($original_file_path);
        }

        
    imagecopyresampled($imageResample$image0000$new_width$new_height$width$height);

        if ( 
    $imgExtension == ".jpg" )
        {
            
    imagejpeg($imageResample$save_path);
        }
        else if ( 
    $imgExtension == ".gif" )
        {
            
    imagegif($imageResample$save_path);
        }
        else if ( 
    $imgExtension == ".png" )
        {
            
    imagepng($imageResample$save_path);
        }
        
    }
    //end thumbnail
    $name2=explode(".",$_FILES["file"]["name"]);
    thumbnail_image("files/Pictures/$name""40""40"""$name2[0]);
        
    $thumb=$url3;
    }
    elseif (
    $category=='Videos18')
    {
    if (isset(
    $ssname)){
    $thumb="files/Screenshots/" $ssname;
    }else{
    $thumb='images/adult.gif';
    }
    }


    $url="files/".$category."/"$name;

    mysql_query("insert into downloads (filename, type, size, category, comments, url, uploadedby, date, ip, thumb, useremail)
            values('
    $name', '$type', '$size', '$category', '$description', '$url', '$user', now(), '$ip', '$thumb', '$useremail')") or die (mysql_error());
    $rsize=round($size2);
    function 
    seo($string) {
    $string strtolower($string);
    $string preg_replace("/[^a-z0-9_\s-]/"""$string);
    $string preg_replace("/[\s-]+/"" "$string);
    $string preg_replace("/[\s_]/""-"$string);
    return 
    $string;
    }
    $query "SELECT * FROM downloads WHERE filename='$name'";
    $result mysql_query($query)  or die(mysql_error());
    $row=mysql_fetch_array($result);
    $id=$row[0];
    $fname=seo($name);
    echo 
    "<font color='#80ff00'>Your file has been uploaded successfully, please upload more below </font><hr><b>Name:</b> <a href='download-$id-$fname.html'>$name</a><br/><b>Size:</b> $rsize kB<br/><b>Category:</b> <a href='$category-1.html'>$category</a><hr>";
    include 
    'upload.php';
          }
    include 
    'foot.php';
    ?>

    #2
    Any error message? then post it here.

    but anyway, don't use this script in production. ;)

    Free Mobile Web Scripts by me: Free Youtube Downloader, Tweets Reader, Facebook Wall Posts Reader
    PHP Tutorials: How to Secure Your PHP Script (PHP SECURITY)
    Want to Develop/Edit your WAP/Web Site? Add me to Gtalk (gmail) 'lakshan1989' or PM me.

    Comment


      #3
      Originally posted by anthrax68 View Post
      Need help on this code, the stream_copy_to_stream function is properly executing because I see the file in folder but in inserting data in mySql is not executing.
      Post your sql

      Comment

      Working...
      X