Orionsbelter Posted December 28, 2012 Share Posted December 28, 2012 Hey all, so i have an image upload script i use however i would like to change the script so that instead of getting the file from an uploaded file it gets it from a url. what would i need to change? <?php session_start(); $username=$_SESSION['username']; include_once"../includes/db_connect.php"; $id=$_POST['id']; $imageNum=$_POST['imageNum']; //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","300"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //get the extension of the file in a lower case format $filename = stripslashes($_FILES['Image1']['name']); $extension = getExtension($filename); $extension = strtolower($extension); define( 'DESIRED_IMAGE_WIDTH', 902 ); define( 'DESIRED_IMAGE_HEIGHT', 677 ); $source_path = $_FILES[ 'Image1' ][ 'tmp_name' ]; //get the extension of the file and check if it is support or not if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {die('This file type is not support, you may only use PNG GIF and JPG files.');} $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024){ die('The File Size Is Too Large!'); } // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // $rand=rand(1000,100000); $newname="$filename"; if($extension == "jpg"){imagejpeg( $desired_gdim, "../images/products/$newname.jpg", 100);} if($extension == "gif"){imagegif( $desired_gdim, "../images/products/$newname.gif", 100);} if($extension == "png"){imagepng( $desired_gdim, "../images/products/$newname.png", 100);} mysql_query("UPDATE `products` SET $imageNum='$newname.$extension' WHERE id='$id'"); header("Location: upload.php?tn=1&id=$id"); // // Add clean-up code here // ?> Quote Link to comment https://forums.phpfreaks.com/topic/272461-php-image-upload-script/ Share on other sites More sharing options...
BrettHartel Posted December 29, 2012 Share Posted December 29, 2012 I cant help you with this, but if the image exists on the web already, you could just store the url in a table then display the url when you want to display the image. Quote Link to comment https://forums.phpfreaks.com/topic/272461-php-image-upload-script/#findComment-1401925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.