Forum Moderators: coopster
This regards a thumb loader in a multiple users environment and loading a path to DB
Facts: as is the script works fine and to see the new loaded img (after the first set) an user needs to refresh its browser
To avoid refreshing from the browser I tried all means (I guess!) from meta refresh to header refresh and location and even using JS
The refresh won’t load the new pic and gives me
“Undefined index: userfile in /export...etc...”
(Keep in mind that the browser refresh button does not generate the error!)
To narrow down the problem I removed any sessions and auth script
and even tried a simple HTML URL link to link back to the same page
and got the same “undefined index”
I FOUND THE CAUSE BUT HAVE NO “PRESCRIPTION”
The img is passed via:
A form print "<input name=\"userfile[]\" type=\"file\" /><br /> ";
And Form Action goes to:
$tot = count($userfile); // that’s the userfile mentioned in the error;
$num = 0;
for($q=0;$q<$tot;$q++){
if ($_FILES['userfile']['name'][$q] == ""); //continue;
$num = $num + 1;
$query = "SELECT index_left_pic FROM group_1";
$result = mysql_query($query);
while($i = mysql_fetch_array($result)){
$new_id = $i['index_left_pic']+1 ;
$new_pic_begin = "$new_id";
$conn= db_connect();
$sql="select random from group_1";
$result= mysql_query($sql,$conn);
while($row=mysql_fetch_array($result))
$random=$row['random'];
}
$jpg=".jpg";
$new_pic=$new_pic_begin.$random.$jpg;
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $new_pic)) {
$index_left_pic="<img src=\"images/thumbs/$new_pic\"> ";
//$query = "update group_1 set index_left_pic ='$index_left_pic' ";
$query = "update group_1 set index_left_pic ='$index_left_pic' where random='$random' ";
mysql_query($query);
} else {
echo "Did not upload, contact Webmaster";
}
So the fix is in keeping the =\"userfile[]\" value passed by the form when refreshing by a script
But why then it works when using the browser refresh button?
How can I keep the “userfile” value while refreshing?
Regards
Henry
I'm thinking it could ba a cache issue. You can try adding these lines at the top of the script that displays the newly uploaded images.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
So the fix is in keeping the =\"userfile[]\" value passed by the form when refreshing by a script
But why then it works when using the browser refresh button?
Are you refreshing or redirecting via PHP? In other words, which of these:
header("Location: thisfile.php");
header("Refresh: 0; url=thisfile.php");
Whatever's happening, you *should* get the undefined index unless you refresh and refreshing reposts the data. If you don't repost, there's nothing in your $_FILES array so the index is undefined.
Out of curiosity, what happens if you make the form action go to "process_photo.php" which, upon success, redirects to "show_photo.php"?
just tried to work on "cache"
I also added just before my session starts
<<<
session_cache_limiter('nocache');
$cache_limiter = session_cache_limiter();
>>
with no better results
I think you are very correct I should find a way to bring $_FILES array on those files
which does not sound realistic without recalling the form?
EDIT: I might try to combine all scripts in one scripts so by essence the form will resubmit?
/EDIT