Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-02-2006, 01:59 AM   PM User | #1
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
Problems uploading a file

Im having problems uploading a file from my form. Here is my script to validate, add to database, and upload to my directory.

PHP Code:
if($_POST['form1sent'] == '1')
    {
        
$catid $_POST['id'];
        
$imagedesc $_POST['imagedesc'];
        
$imagename $_POST['imagename'];
        if((
strlen($imagename) < 3) || (strlen($imagename) > 30) )
        {
            
$length strlen($imagename);
            
badrequest("Your tutorial name must be between 3 and 30 characters. Your title was ".$length." characters long.");
        }
        else
        {
            if(
strlen($imagedesc) > 65535)
            {
                
$length strlen($imagedesc);
                
badrequest("Your tutorial description must be less than 65535 characters. Your description was ".$length." characters long.");
            }
            else
            {
                
clearstatcache();
                
$size filesize($_FILES['image']['tmp_name']);
                list(
$width,$height,$type)=getimagesize($_FILES['image']['tmp_name']); 
                if(
$type != (1||2||3||6) || $size >= 1101064
                { 
                    
badrequest("Your image may only be in the formats gif, jpg, png, or bmp. Your file must also be less then 1.5 megabytes.");
                }
                else
                {
                    
$types = array(
                       
=> 'GIF',
                       
=> 'JPG',
                       
=> 'PNG',
                       
=> 'SWF',
                       
=> 'PSD',
                       
=> 'BMP',
                       
=> 'TIFF(intel byte order)',
                       
=> 'TIFF(motorola byte order)',
                       
=> 'JPC',
                       
10 => 'JP2',
                       
11 => 'JPX',
                       
12 => 'JB2',
                       
13 => 'SWC',
                       
14 => 'IFF',
                       
15 => 'WBMP',
                       
16 => 'XBM'
                   
);
                    
$ext $types[$type];
                    
$uploaddir ROOT."images/";
                    
$time date('ymdHisB');
                    
$uploadfile $uploaddir."/".$time.$ext;
                    
$location "http://images.image-space.net/".$time.$ext;
                    
move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
                    
                    
$catid2 $db->escape($catid);
                    
$imagedesc2 =  $db->escape($imagedesc);
                    
$imagename2 =  $db->escape($imagename);
        
                    
$db->query("INSERT INTO tutorials 
                    (`parentid`,`dateuploaded`,`name`,`description`,`location`)
                    VALUES
                    ('"
.$catid2."',now(),'".$imagename2."','".$imagedesc2."','".$location."')") or badrequest("An error occured uploading your image.");
                    
redirect(ROOT.'member/image_sub.php'"Image uploaded successfully..");
                }
            }
        }
    } 
My form looks like this:

Code:
<form action="image_sub.php" enctype="multipart/form-data" method="post">
	<input type="hidden" name="form1sent" value="1" />
	<p>
		<b>Image Title:</b><br />
		<input type="text" name="imagename" /><br /><br />
		<b>Choose the category:</b><br />
		<select class="select" name="id">
			<optgroup class="maincat" label="Digital Art">
				<option class="sub first" value="2">3D Art</option>
				<option class="sub" value="3">Drawings</option>
				<option class="sub" value="4">Miscellaneous</option>
				<option class="sub" value="5">Photo Manipulation</option>
				<option class="sub" value="6">Wallpapers</option>
				<optgroup class="subcat" label="Internet Use">
					<option class="subcatsub first" value="8">Signatures</option>
					<option class="subcatsub" value="9">Avatars</option>
				</optgroup>
			</optgroup>
			<optgroup class="maincat" label="Photography">
				<option class="sub first" value="13">Architecture</option>
				<option class="sub" value="12">Portrait</option>
				<option class="sub" value="11">Landscape</option>
			</optgroup>
		</select>&nbsp;
		<br />
		<br />
		<b>Select your file:</b><br />
		<input type="file" class="fileupload" name="image" />
		<br />
		<br />
		<b>Description:</b><br />
		<textarea name="imagedesc" cols="40" rows="6"></textarea>
		<br />
		<br />
		<input type="submit" value="Upload" />
	</p>
</form>
Im not getting any of my errors, or errors from php. What is happening, is that the page just loads and loads. It has been "loading" for 34 minutes and the file is a tad over 1 megabyte. Ive uploaded files this large by form before and it has never taken more than 45 seconds. Any ideas what could be going wrong?
thesavior is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:10 PM.


Advertisement
Log in to turn off these ads.