Jump to content

Help with Image Upload


mat3000000

Recommended Posts

It will add the 'FILES' folder if it isn't there, but just refreshes the page, displaying no errors, without adding anything to the folder???

 

As you can probably see I have three file slots for users, I want to fill the next available slot up, and if no slots, display error 2 ($e=2; - Delete a file to make space)

 

//^^GET VARIABLES SUCH AS USERNAME ETC.

if(isset($_POST['uploadfile'])){

if(is_dir("files/$username/FILES/")){}else{mkdir("files/$username/FILES/");}

   if (is_uploaded_file($_FILES['file']['tmp_name'])) {
   
   $name = $_FILES['file']['name'];

      if ($file != "application/pdf" || substr(strrchr($file, '.'), 1) != "pdf" || substr(strrchr($file, '.'), 1) != "jpg" || $file != "image/jpeg" || $file != "image/pjpeg") {
         $errors[] = 'File must be in PDF or JPEG format';
      } 
  else if($_FILES['file']['size'] > 256000){$errors[] = 'File must be under 250KB';}
  
 else {
	 $name1 = substr($name, 0, strrpos($name, '.')); 
	 $ext = strtolower(substr(strrchr($name, '.'), 1));
	 $name = $name1.'.'.$ext;


	 $res = mysql_query("SELECT username,file1,file2,file3 FROM `files` WHERE `username`='$username'");
		$row = mysql_fetch_array($res);
		$f1 = $row['file1'];
		$f2 = $row['file2'];
		$f3 = $row['file3'];

		if($f1==''){

					$result = move_uploaded_file($_FILES['file']['tmp_name'], "files/$username/FILES/$name");
					 if ($result == 1){ 
					 $time = time();
					 $t=1;
					 mysql_query("UPDATE files SET file1='$name', file1_val='0', file1_added='$time' WHERE username='$username'");
					 	}else $e=1;

		}else if(empty($f2)){

					$result = move_uploaded_file($_FILES['file']['tmp_name'], "files/$username/FILES/$name");
					 if ($result == 1){ 
					 $time = time();
					 $t=1;
					 mysql_query("UPDATE files SET file2='$name', file2_val='0', file2_added='$time' WHERE username='$username'");
						}else $e=1;

		}else if(empty($f3)){

					$result = move_uploaded_file($_FILES['file']['tmp_name'], "files/$username/FILES/$name");
					 if ($result == 1){ 
					 $time = time();
					 $t=1;
					 mysql_query("UPDATE files SET file3='$name', file3_val='0', file3_added='$time' WHERE username='$username'");
						}else $e=1;

		}else{$e=2;}


      } 
   } 
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.