Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2007, 10:58 PM
Wizardjv Wizardjv is offline
 
Join Date: Feb 2006
Posts: 111
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default need some php help

Ok so I have this code I made for transloading.

HTML Code:
<?php

if($_POST[sourceurl] == "")

{

print "Please enter the source URL";

}

else

{



$image_url = "$_POST[sourceurl]";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $image_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

// Getting binary data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

$image = curl_exec($ch);
curl_close($ch);

// output to browser
header("Content-type: image/jpeg");
print $image;

}
?>

<html>
<form name="input" method="post" action="curl.php">

File:
<input type="text" name="sourceurl">
<input type="submit" value="Submit">
</form>
</html>
It works fine now I wanna split the php curl up and send the image to another file with code instead of printing to browser.

I have no problem splitting it up. But I cant seem to send it to the other code.

here is the other code.

HTML Code:
<?

    // get variables for fields on upload screen
    $thefile = $_FILES['thefile'];
    $tos = $_POST['tos'];

    $currentip = $_SERVER['REMOTE_ADDR'];
    $messages = "";

    // check for blocked ip address
    if ($currentip != "") {
        $link = mysql_connect($db_server, $db_user, $db_password) or die("Could not connect to the database.");
        mysql_select_db($db_name) or die("Could not select the database.");
        $query = "select ip from blocked where ip = '$currentip'";
        $result = mysql_query($query) or die("Query failed.");
        $num_rows = mysql_num_rows($result);
        if ($num_rows > 0) {
            $messages .= "Your IP address (" . $currentip . ") has been blocked from using this service.<br><br>";
        }
    }

    // check for a file
    if (!isset($thefile) || $thefile['name'] == "") {
        $messages .= "You must select a file to upload using the &quot;Browse&quot; button.<br><br>";
    }

    if ($messages == "") {
        // check for valid file type
        if (!in_array_nocase($thefile['type'], $valid_mime_types)) {
            $messages .= "<em>" . $thefile['name'] . "</em> is not in a valid format (" . $valid_mime_types_display . ").<br><br>";
        }

        // check for valid file extension
        $thefile['name'] = strtolower($thefile['name']);
        $file_ext = substr($thefile['name'], strlen($thefile['name']) - 3, strlen($thefile['name']));
        // fix for JPEG names files
        if ($file_ext == "peg") {
            $file_ext = "jpg";
        }
        if (!in_array_nocase($file_ext, $valid_file_ext)) {
            $messages .= "<em>" . $thefile['name'] . "</em> (".$file_ext.") does not have a valid file extension (" . $valid_mime_types_display . ").<br><br>";
        }

        // check for valid file size
        if ($thefile['size'] > ($max_file_size_kb * 1024)) {
            $messages .= "<em>" . $thefile['name'] . "</em> is bigger than the allowed file size of " . $max_file_size_kb . " K.<br><br>";
        }
    }

    // save the file, if no error messages
    if ($messages == "") {
        $max_file_size_byes = $max_file_size_kb * 5024;

        // SAVE THE PICTURE
        $newFileName = newImageName($thefile['name']);
        $newFile = $server_dir . $newFileName;
        $newFileUrl = $image_url . $newFileName;
        $newFileUrlLink = $server_save_directory . $newFileName;
        if ($file_ext == "jpg" || $file_ext == "png" || $file_ext == "gif") {
            $tnFileName = "tn_" . substr($newFileName, 0, strlen($newFileName) - 3) . "jpg";
            $tnFile = $server_dir . $tnFileName;
            $tnFileUrl = $image_url . $tnFileName;
        } else {
            $tnFileName = "";
            $tnFile = "";
            $tnFileUrl = "";
        }
        $filesize = $thefile['size'];
        $newID = "";
        if (!@copy($thefile['tmp_name'], $newFile)) {
            $messages .= "An unexpected error prevented your file from being saved. Please try again.";
        } else {
            // add to database
            $query = "INSERT INTO images (filename, tn_filename, filepath, ip, filesize) VALUES ('$newFileName', '$tnFileName', '$server_save_directory', '$currentip', $filesize)";
            mysql_query($query) or die("Database entry failed.");
            $newID = mysql_insert_id();
        }

        if ($file_ext == "jpg" || $file_ext == "png" || $file_ext == "gif") {
            if ($file_ext == "jpg") {
                $source_id = imagecreatefromjpeg($newFile);
            } elseif ($file_ext == "png") {
                $source_id = imagecreatefrompng($newFile);
            } elseif ($file_ext == "gif") {
                $source_id = imagecreatefromgif($newFile);
            }

            $true_width = imagesx($source_id);
            $true_height = imagesy($source_id);

            // create thumb
            if ($true_width > $thumbnail_size_max || $true_height > $thumbnail_size_max) {
                if ($true_width >= $true_height) {
                    $dest_width = $thumbnail_size_max;
                    $dest_height = ($dest_width / $true_width) * $true_height;
                } else {
                    $dest_height = $thumbnail_size_max;
                    $dest_width = ($dest_height / $true_height) * $true_width;
                }
                if ($thefile['type'] == "image/jpeg" || $thefile['type'] == "image/pjpeg") {
                    $target_id = imagecreatetruecolor($dest_width, $dest_height);
                } elseif ($thefile['type'] == "image/png" || $thefile['type'] == "image/x-png") {
                    $target_id = imagecreatetruecolor($dest_width, $dest_height);
                } else {
                    $target_id = imagecreatetruecolor($dest_width, $dest_height);
                }
                $target_pic = imagecopyresized($target_id, $source_id, 0, 0, 0, 0, $dest_width, $dest_height, $true_width, $true_height);
   
                // create a thumbnail in JPEG format
                imagejpeg($target_id, $tnFile, $thumbnail_quality);
   
                imagedestroy($target_id);
            } else {
                copy($newFile, $tnFile);
            }
        }
    }
    mysql_close($link);

    // create URL links to display to user
    $showURL1 = false;  // image on hosted page - image only
    $showURL2 = false;  // direct link to file - all
    $showURL3 = false;  // HTML for img - image only
    $showURL4 = false;  //  tags - image only
    $showURL5 = false;  // thumbnail pic - image only

    // determine flags
    $showURL2 = true;
    if ($file_ext == "jpg" || $file_ext == "gif" || $file_ext == "png" || $file_ext == "bmp") {
        $showURL1 = true;
        $showURL3 = true;
        $showURL4 = true;
    }
    if ($file_ext == "jpg" || $file_ext == "gif" || $file_ext == "png") {
        $showURL5 = true;
    }

    function newImageName($fname) {
        $timestamp = time();
        $new_image_file_ext = substr($fname, strlen($fname) - 3, strlen($fname));
        if ($new_image_file_ext == "peg") {
            $ext = ".jpg";
        } else {
            $ext = "." . $new_image_file_ext;
        }
        $newfilename = randString() . substr($timestamp, strlen(timestamp) - 4, strlen(timestamp)) . $ext;
        return $newfilename;
    }

    function randString() {
        $newstring="";
        while(strlen($newstring) < 3) {
            $randnum = mt_rand(0,61);
            if ($randnum < 10) {
                $newstring .= chr($randnum + 48);
            } elseif ($randnum < 36) {
                $newstring .= chr($randnum + 55);
            } else {
                $newstring .= chr($randnum + 61);
            }
        }
        return $newstring;
    }

    function in_array_nocase($item, $array) {
        $item = &strtoupper($item);
        foreach($array as $element) {
            if ($item == strtoupper($element)) {
                return true;
            }
        }
        return false;
    }

?>
Yeah I know the variables need some editing. But the problem is im having is bridging the 2 together. So I figure maybe someone can give me hand

I acctually had it working without the curl. But my host said that due to security reasons they wont allow how I was doing it. Use curl or dont do it. So ...im stuck for moment
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:46 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03175 seconds
  • Memory Usage 2,239KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete