onthespot Posted August 6, 2009 Share Posted August 6, 2009 How do i change the name of the file here to a variable? $imagename = $_FILES['new_image']['name']; I want the name part to be a variable called $subject any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/169024-solved-simple-problem/ Share on other sites More sharing options...
wildteen88 Posted August 6, 2009 Share Posted August 6, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/169024-solved-simple-problem/#findComment-891779 Share on other sites More sharing options...
onthespot Posted August 6, 2009 Author Share Posted August 6, 2009 Ahh i see, i have tried this but it loses the .jpg in the image destination folder. Quote Link to comment https://forums.phpfreaks.com/topic/169024-solved-simple-problem/#findComment-891782 Share on other sites More sharing options...
onthespot Posted August 6, 2009 Author Share Posted August 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/169024-solved-simple-problem/#findComment-891783 Share on other sites More sharing options...
wildteen88 Posted August 6, 2009 Share Posted August 6, 2009 Use $imagename = $subject . '.jpg'; Quote Link to comment https://forums.phpfreaks.com/topic/169024-solved-simple-problem/#findComment-891784 Share on other sites More sharing options...
onthespot Posted August 6, 2009 Author Share Posted August 6, 2009 Thankyou perfect Quote Link to comment https://forums.phpfreaks.com/topic/169024-solved-simple-problem/#findComment-891785 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.