[code=php]$temp_image_name = $_FILES[ $field ][ ‘name’ ];
$num = 1;
while (1) {
if (file_exists(“http://linksku.com/wp-content/upload/” . $temp_image_name)) {
if ($num == 1) {
preg_match(‘/.[a-zA-Z]{3,4}$/’,$temp_image_name,$match);
$extension = $match[0];
}
$temp_image_name = preg_replace(‘/.[a-zA-Z]{3,4}$/’,”,$temp_image_name);
if ($num > 1)
$regex = ‘/’.$num.’$/’;
if ($num > 1)
$temp_image_name = preg_replace($regex,”,$temp_image_name);
$num = $num + 1;
$temp_image_name = $temp_image_name.$num;
} else {
if ($num!=1)
$temp_image_name = $temp_image_name.$extension;
break;
}
}
I want this to create an unique file name, but this isn’t working. I know there are much more efficient ways of writing this.
[code=php]
$temp_image_name = $_FILES[ $field ][ 'name' ];
$num = 1;
while ($num) {
if (file_exists("http://linksku.com/wp-content/upload/" . $temp_image_name)) {
if ($num == 1) {
preg_match('/.[a-zA-Z]{3,4}$/',$temp_image_name,$match);
$extension = $match[0];
}
$temp_image_name = preg_replace('/.[a-zA-Z]{3,4}$/','',$temp_image_name);
if ($num > 1)
$regex = '/'.$num.'$/';
if ($num > 1)
$temp_image_name = preg_replace($regex,'',$temp_image_name);
$num = $num + 1;
$temp_image_name = $temp_image_name.$num;
} else {
if ($num!=1)
$temp_image_name = $temp_image_name.$extension;
break;
}
$num++;
}
[/code]
[code=php]$num = 2;
while (1) {
if (file_exists("../wp-content/uploads/wp-post-image/" . $temp_image_name)) {
if ($num == 2) {
preg_match('/.[a-zA-Z]{3,4}$/',$temp_image_name,$match);
$extension = $match[0];
}
$temp_image_name = preg_replace('/.[a-zA-Z]{3,4}$/','',$temp_image_name);
if ($num > 2)
$regex = '/'.$num.'$/';
if ($num > 2)
$temp_image_name = preg_replace($regex,'',$temp_image_name);
$temp_image_name = $temp_image_name.$num;
} else {
if ($num > 2)
$temp_image_name = $temp_image_name.$extension;
break;
}
$num++;
} [/code]
So I can use /public_html/forum/styles/prosilver/template/overall_header.html in a PHP include?[/QUOTE]
Yes, that would correspond to:
http://linksku.com/forum/styles/pros...ll_header.html
[/quote]
However, since a php include requires a php file, it wouldn't work for that particular .html file you're requesting in the above code. For that html file you'd need to use something likefile_get_contents() orfile() .[/QUOTE]
However, since a php include requires a php file, it wouldn't work for that particular .html file you're requesting in the above code. For that html file you'd need to use something like file_get_contents() or file().
[/quote]
The include() statement includes and evaluates the specified file.
[/quote]
This is also not true. file_get_contents() or file() will read the contents of a file to a variable.include will (as on php.net):[/QUOTE]
My bad, I was editing that file when I used it as an example, and I forgot that it wasn't PHP :o. Thanks for your explanation, the only part where I'm still confused is, how does the PHP processor distinguish the difference between a relative URL and a relative filesystem path? They're both written the same way, right (correct me from wrong).[/QUOTE]
Not true in most cases. In PHP, the include statement takes either a relative path or an absolute one. The example provided used an absolute path (on *nix systems) that (more than likely) does not exist. A "/" at the beginning (on a *nix system) makes PHP start at the root of the file system.[/QUOTE]
My bad, I was editing that file when I used it as an example, and I forgot that it wasn't PHP :o. Thanks for your explanation, the only part where I'm still confused is, how does the PHP processor distinguish the difference between a relative URL and a relative filesystem path? They're both written the same way, right (correct me from wrong).[/QUOTE]
Thanks. What confused me was that some articles online called "../../file.php" an relative URL.
Another question is, if I include a file containing functions by its URL, can I still access the functions?[/QUOTE]
[CODE]/public_html/wp-content/uploads/wp-post-thumbnail/Balloon-Explode.jpg
/public_html/wp-content/uploads/wp-post-thumbnail/Balloon-Explode2.jpg
/public_html/wp-content/uploads/wp-post-thumbnail/Balloon-Explode2.jpg
/public_html/wp-content/uploads/wp-post-thumbnail/Balloon-Explode2.jpg[/CODE]
[code=php]$num = 2;
while (1) {
if (file_exists("../wp-content/uploads/wp-post-image/" . $temp_image_name)) {
if ($num == 2) {
preg_match('/.[a-zA-Z]{3,4}$/',$temp_image_name,$match);
$extension = $match[0];
}
$temp_image_name = preg_replace('/.[a-zA-Z]{3,4}$/','',$temp_image_name);
if ($num > 2)
$regex = '/'.$num.'$/';
if ($num > 2)
$temp_image_name = preg_replace($regex,'',$temp_image_name);
$temp_image_name = $temp_image_name.$num;
} else {
if ($num > 2)
$temp_image_name = $temp_image_name.$extension;
break;
}
$num++;
}[/code]
0.1.9 — BETA 5.18