PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Mon Mar 01, 2004 2:48 pm
i have written a image upload script for a image gallery that i designed, and it works fine when i try to upload a .....say 200kb file, but around 6-700kb it gives me the max execution time error. but i know that is not a filesize problem cause i can upload a 2.00mb file on the same server.
heres the code....
Code: Select all
if(!isset($_POST['submit'])){
Print <<< EOT
<form enctype="multipart/form-data" method="POST" action="index.php?l=admin_qwertylx.php&admin=newimg">
Image: <input type="file" name="userfile" size="33"><br>
Info: <textarea cols=36 rows=10 name=info></textarea><br>
Choose gallery: <select name=cat>
EOT;
$query = mysql_query("SELECT * FROM cat");
while($array = mysql_fetch_array($query))
{
Print <<< EOT
<option value={$array['name']}>{$array['name']}</option>
EOT;
}
Print <<< EOT
</select><br>
<input type="submit" value="Submit" name="submit">
</form>
EOT;
}
else{
$cat = $_POST['cat'];
$info = $_POST['info'];
$filename = eregi_replace(" ","%20",$_FILES["userfile"]["name"]);
$stripspaces = eregi_replace("_"," ",$_FILES["userfile"]["tmp_name"]);
$name=str_replace(chr(32),chr(95),$_FILES['file']['name']);
if (is_uploaded_file($stripspaces)) {
copy($_FILES["userfile"]["tmp_name"], "gal/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}
$sql = mysql_query("INSERT INTO images (cat, info, src) VALUES('$cat', '$info', '$filename')");
if($sql){
echo "Image added";
}
elseif(!$sql){
echo "Problem......Image not added";
}
else{
echo "Problem executing the script!";
}
}
any thoughts as too why this is hapening????
THANX dull
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Mar 01, 2004 2:50 pm
The script maybe just exceeding the default execution time of 30seconds. Try using
http://php.net/set_time_limit
Eg, set_time_limit(0);
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Mon Mar 01, 2004 2:53 pm
so it can just crap out just because it exceeds the time limit, but it takes a hole heck of alot longer then 30 seconds to get that error, sometimes minutesbut ill try it out.....thanx
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Tue Mar 02, 2004 3:20 pm
well i tried to use set_time_limit() but to no avail, it did not work
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Mar 02, 2004 4:00 pm
Is there anything unique about a file(s) that won't upload? ie file name or type as compared to those that upload ok?
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Tue Mar 02, 2004 4:21 pm
try putting this in there and see if it helps any...
<INPUT type=hidden value=2000000 name=MAX_FILE_SIZE><input type="file" name="userfile" size="33">