Call-911 Posted January 14, 2011 Share Posted January 14, 2011 Hello All, In below script, I'm using another script called "SimpleImage.php" to upload and resize photos for a news site. The problem comes with renaming the photos. I need to name the photo based off of the story id. I have everything right to get the story id, but saving it as the variable is what's confusing me. Here's what I have: <?php include ("newsconnection.php");?> <?php $picturename = $_POST['newstoryid']; include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['uploaded_image']['tmp_name']); $image->resizeToWidth(300); $image->save('$picturename'); ?> It's the $image->save('$picturename'); line that's messing me up. Any help would be great!! Link to comment https://forums.phpfreaks.com/topic/224432-variables-not-working-right/ Share on other sites More sharing options...
beegro Posted January 14, 2011 Share Posted January 14, 2011 You're using single quotes around a PHP variable $image->save('$picturename'); That treats the string literally instead of as the $picturename value. Try $image->save($picturename); Link to comment https://forums.phpfreaks.com/topic/224432-variables-not-working-right/#findComment-1159360 Share on other sites More sharing options...
Call-911 Posted January 14, 2011 Author Share Posted January 14, 2011 Would saving it in a directory and as a .jpg be: $image->save('uploadedphotos/'$picturename'.jpg'); or should I include that in the variable? $picturename = 'uploadedphotos/'$_POST['newstoryid']'.jpg'; Link to comment https://forums.phpfreaks.com/topic/224432-variables-not-working-right/#findComment-1159411 Share on other sites More sharing options...
chronister Posted January 14, 2011 Share Posted January 14, 2011 $image->save('uploadedphotos/'.$picturename.'.jpg'); You have to have the additional periods to properly concatenate the string. Link to comment https://forums.phpfreaks.com/topic/224432-variables-not-working-right/#findComment-1159415 Share on other sites More sharing options...
Call-911 Posted January 14, 2011 Author Share Posted January 14, 2011 Perfect! Thanks guys! Link to comment https://forums.phpfreaks.com/topic/224432-variables-not-working-right/#findComment-1159467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.