Friday, 15 June 2012

php - How to make image name with post_id wordpress -



php - How to make image name with post_id wordpress -

i have project auto create images each post id have save each separated image associated each post , image name should post id tried these methods not succeed

wp-content/uploads/2014/<?php the_id(); ?>.png

===================================

$id = get_the_id();

then

file_put_contents('wp-content/uploads/2014/text-$id.png', $image);

so need php method save image post id in ths line

file_put_contents('wp-content/uploads/2014/imagenamepostidhere.png', $image);

thanks

if $image fine, simple utilize concatenation or utilize double quotes utilize id:

file_put_contents('wp-content/uploads/2014/text-$id.png', $image); // you're using single quotes, variables not interpolated

either:

$id = get_the_id(); file_put_contents('wp-content/uploads/2014/text-'.$id.'.png', $image);

or

file_put_contents("wp-content/uploads/2014/text-$id.png", $image);

note: assuming have proper permissions.

php wordpress imagesource

No comments:

Post a Comment