-IMP
Blank Array Indecies?
Moderator: General Moderators
- IceMetalPunk
- Forum Commoner
- Posts: 71
- Joined: Thu Jul 07, 2005 11:45 am
Blank Array Indecies?
*PROBLEM SOLVED, BUT THERE'S ANOTHER PROBLEM! SCROLL DOWN
*
-IMP

-IMP
Last edited by IceMetalPunk on Wed Jul 20, 2005 8:31 pm, edited 4 times in total.
Do you mean a file someone has uploaded when you say "a file online"? Coz if you do, don't rely on the extension.. might be a Mac or a Unix user, their files don't necessarily have extensions in the file name. Instead, use $_FILES['userfile']['type'] to get the MIME type:
http://uk.php.net/features.file-upload
Each image will be one of:
GIF: image/gif
JPG: image/jpeg
PNG: image/png
Alternatively, calling getimagesize() returns the type along with other info.
http://uk.php.net/features.file-upload
Each image will be one of:
GIF: image/gif
JPG: image/jpeg
PNG: image/png
Alternatively, calling getimagesize() returns the type along with other info.
- IceMetalPunk
- Forum Commoner
- Posts: 71
- Joined: Thu Jul 07, 2005 11:45 am
Nope, not an uploaded file, just a URL. But I found the problem: When converting the URLs into an array, some end up blank.... maybe someone can help me figure out why? Here's the relevant (sp?) code:
All the other info is stored okay, but when I convert it to the urls array, even though there are only 3 URLs after the 4th line in the file, I end up with an array like this (this is a pseudo-array):
Notice the 2 blank spots at the end? I don't know why they're appearing, but they're messing everything up, and as there may be more than 3 URLs later, I can't just tell it to stop at array index 2.
-IMP

Code: Select all
$info=file_get_contents("mri".$uid.".txt");
$info=explode("\r\n",$info);
$w=$info[0];
$h=$info[1];
$num=$info[2];
$pwd=$info[3];
$urls="";
for ($i=4; $i<count($info); $i+=1) {
$urls.=$info[$i]."\r\n";
}
$urls=explode("\r\n",$urls);
for ($i=0; $i<$num; $i+=1) {
$imgs[$i]=$urls[rand(0,count($urls)-1)];
}Code: Select all
[0]=>URL1
[1]=>URL2
[2]=>URL3
[3]=>
[4]=>-IMP