Jump to content

Recommended Posts

Well that line assigns the variable $imagename to the uploaded file name. So if your uploaded file is somefile.txt then $imagename will be set as somefile.txt

 

If you want the uploaded file to be named the value of the $subject variable you'd use

$imagename = $subject;

if(isset($_POST['submit']))
		{


			if (isset ($_FILES['new_image']))
			{

				$imagename = $subject;
				$source = $_FILES['new_image']['tmp_name'];
				$target = "images/news/".$imagename;
				move_uploaded_file($source, $target);

				 if (move_uploaded_file($source, $target) == FALSE)
       echo "COULDNT MOVE FILE";

				$imagepath = $imagename;
				$save = "images/news/" . $imagepath; //This is the new file you saving
				$file = "images/news/" . $imagepath; //This is the original file

				list($width, $height) = getimagesize($file) ;

				$modwidth = 150;

				$diff = $width / $modwidth;

				$modheight = $height / $diff;
				$tn = imagecreatetruecolor($modwidth, $modheight) ;
				$image = imagecreatefromjpeg($file) ;
				imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

				imagejpeg($tn, $save, 100) ;

				$save = "images/news/sml_" . $imagepath; //This is the new file you saving
				$file = "images/news/" . $imagepath; //This is the original file

				list($width, $height) = getimagesize($file) ;

				$modwidth = 80;

				$diff = $width / $modwidth;

				$modheight = $height / $diff;
				$tn = imagecreatetruecolor($modwidth, $modheight) ;
				$image = imagecreatefromjpeg($file) ;
				imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

				imagejpeg($tn, $save, 100) ;
				echo "Large image: <img src='images/news/".$imagepath."'><br>";
				echo "Thumbnail: <img src='images/news/sml_".$imagepath."'>";

			}
		}

 

There is the code, I am trying to get the name at the end to be the variable $subject, but .jpg

Could you help?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.