Jump to content


Photo

Can't get file upload script working :/


  • Please log in to reply
3 replies to this topic

#1 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 05 August 2006 - 10:55 AM

Hi there. Here is my code: (It is straight from a tutorial site)

Makeaj.php
------------

<form action="makeajcom.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>


Makeajcom.php
---------------


<?php

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
      "/uploads/{$_FILES['uploadFile'] ['name']}")

?>


///////////--------------//////////////

I figured it would be easy to get this bit done, but it doesnt seem to be working!
uploads is a directory below both php files..

Any help would be really appreciated





#2 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 05 August 2006 - 11:36 AM

Well because my previous post was way to long and had way to much options, I filtered it a bit and came up with this, It still need some altering though.. but it should work


<?php
function Upload($File, $UploadFolder='', $NewFilename='', $UploadExtFilter='', $UploadMaxSize='') {
	if (substr($UploadFolder, -1) != '/') {
		$UploadFolder .= '/';
	}
	if (!is_dir($UploadFolder)) {
		// Error message comes here..., or try to create the folder
	}
	if (!is_writable($UploadFolder)) {
		// Error message comes here..., or make it writable
	}
	if (is_uploaded_file($File['tmp_name'])) {
		$Filesize = $File['size'];
		$Filename = $File['name'];
		if (!preg_match('/\\.('.$UploadExtFilter.')$/i', $Filename)) {
			if ($Filesize > $UploadMaxSize) {
				// file to big..
			}
			if ($NewFilename) {
				$Filename = $NewFilename;
			}
			if (file_exists($UploadFolder . $Filename)) {
				// Oeps already exists...
			}
			if (move_uploaded_file($File['tmp_name'], $UploadFolder . $Filename)) {
				// Success
				return true;
			} else {
				// No success
				return false;
			}
		} else {
			// Extensions not allowed
		}
	}
}

if ($_POST['submit']=='Upload') {
	if (Upload($_FILES['uploadIt'], '/upload/', 'my_file.txt', 'bat|com|php', 8000)) {
		echo 'jipii';
	} 
}
?>

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadIt"> <input type="submit" name="submit" value="Upload">
</form>


#3 xec

xec
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 05 August 2006 - 01:39 PM

// THIS IS WORKING UPLOAD SCRIPT , I AM USING IT....
//------------------------------------------------

if(strlen($HTTP_POST_FILES['ufile']['name']) <1)
{
echo ("ERROR ! No file to upload" );
exit();
}


$upload_path = $HTTP_POST_FILES['ufile']['name'];
//echo $upload_path;

/*if(!is_dir($_POST['path1']))
{
echo ' ERROR ! Path not defined properly';
exit();
}*/
$store_dir = "/upload/";

/*if( !is_dir($store_dir) )
{
  echo("Specified directory is not valid... Exiting");
  @unlink($HTTP_POST_FILES['ufile']['tmp_name']);
  exit();
}*/

if( copy($HTTP_POST_FILES['ufile']['tmp_name'],$store_dir.$HTTP_POST_FILES['ufile']['name']) )
{
  echo("Uploaded ".$HTTP_POST_FILES['ufile']['name']." successfully.");
}

/*if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $upload_path))
{
  echo 'FILES ,'.$HTTP_POST_FILES['ufile']['name'].' uploaded successfully';
}*/
else
  {
  echo 'ERROR : error in uploading ';
  }

unlink($HTTP_POST_FILES['ufile']['tmp_name']);

#4 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 06 August 2006 - 02:29 AM

Hey guys, the basics are now complete, however still one last hurdle to tackle,

When the user locates this persons journal page I need to display all the pictures for this journal.
Now when the user uploaded the pictures they were stored in a folder /upload and each picture had the name
of the journaltitle then a number e.g

beachtrip1.jpg beachtrip2.jpg

How do I first check to see if pictures were uploaded and then display them?...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users