Hey,
Here is the situation: I have a gallery of images that are being displayed with javascript that requires the image files to be saved as img1, img2, img3, etc. I am currently trying to write the php code that keeps track of the number of image files and allows more images to be added into the gallery by a user. The only problem that I can't get past is saving the images in a proper format using the string "image" and then the variable number of images in the folder. Any combination of "." and the string and variable just print as the string only. Help please?

Current code:

$path = "img" . "$filenum";

Well, I am thoroughly shamed. The code I have posted is correct, save that the variable I was using is $fileNum, not $filenum. Apologies for the confusion

$fileNum does not need to be dquoted,
in double quotes the php parser will search text, for variables
all of these work

$path = "img$fileNum";
$path = "img".$fileNum;
$path = 'img'.$fileNum;

putting the variable inside quotes is slower (infinitessimally) than leaving it outside where it belongs, above line3 (single quoted text) is fastest, the php parser does not waste time looking for variables where none exist.
May not matter for 1 image, may matter for many images

Member Avatar for rajarajan2017

Below denotes the string and a variable by differentiating with quotes.

$path = "img" . $filenum;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.