Jump to content

Problem with uploading a file.


Johns3n

Recommended Posts

Hi again folks at PHPfreaks!

First off thanks for all the speedy answers i've gotten in the past when I had problems with either PHP and/or MySQL, I really appreciate you taking your time to help out us less-so-good-at-php designers out there :)

 

With that said, I have some problems with a file upload script that I wrote, please bear in mind that the script is copied from another file of mine where it actually works, so I am abit staggered to see it isn't working now :(

 

I made sure the folder where it tries put file is CHMOD'ed to "777" for full write access. So I am hoping that you maybe able to spot the error! Please notice that I run most of my scripts from the same file using _GET urls to determine what scripts run when and where.. like so:

 

"upload.php?action=upload" <- Shows the Form where to upload the file
"upload.php?action=insert" <- Runs the script to actually upload the file from the form

 

But the above should be evident in the script below :) So hope that you maybe can see where I am wrong?

 

elseif($action == "upload")
{
echo "<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>

<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<meta name='robots' content='noindex,nofollow' />
<link href='css/admin.css' rel='stylesheet' type='text/css' media='all' />
<title>LÖRK(SOURCE) » Administrations Værktøj</title>
<script type='text/javascript' src='js/javascript.js'></script>

<body>
<div id='loading' style=\"display: none;\">
		<div id='overlay'></div>
		<div id='loading_progress'>
			<h2>Vent venligst</h2>
			<h3>Uploader...</h3>
			<img src='gfx/progress.gif' alt='Henter' />
			<p>Dit indhold indsættes nu i databasen.</p>
			<p>Dette kan tage nogle minutter alt efter din internets forbindelse.</p>
		</div>
</div>
<div id='workarea'>
<div id='form'>
	<form action='upload.php?action=insert' method='POST'>
	<input type='text' name='fakeupload' class='fake' />
	<input type='file' name='uploadedfile' class='real' onchange='this.form.fakeupload.value = this.value;' />
	<input type='submit' onclick=\"showStuff('loading');\" value='UPLOAD' class='upload_btn' />
	<p>Klik på det hvide tekst felt for at vælge et billed til upload</p>
	</form>
	<a href=''
</div>

</body>
</html>";
}
elseif($action == "insert")
{
$file=$_FILES['uploadedfile']['name'];

// Angiv fil sti og fil navn hvor plakaten skal gemmes
$target_path = "../uploads/images/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

// Hvis filen flyttes med succes vis meddelse
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
{	
	// Create SQL query to insert blog post into posts table
	$insert_file="INSERT INTO ". $db_prefix ."uploads (filename) VALUES ('$file')";

	// Execute query to create blog post in posts table
	mysql_query($insert_file,$con);

	// Definere sti og fil navn på plakat der skal resizes
	$file_path="../uploads/images/$file";

	// Definere sti og fil navn på plakat der skal resizes til infoskærms brug
	$thumb_path="../uploads/images/thumb_$file";

	// Resize plakaten med simpleimage
	include('js/simpleimage.php');
	$image = new SimpleImage();

	// Resize Plakaten til infoskærm
	$image->load($file_path);
	$image->resize(145,160);
	$image->save($thumb_path);

	echo "<?xml version='1.0' encoding='utf-8'?>
	<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
	<html xmlns='http://www.w3.org/1999/xhtml'>

	<head>
	<meta http-equiv='content-type' content='text/html; charset=utf-8' />
	<meta name='robots' content='noindex,nofollow' />
	<link href='css/admin.css' rel='stylesheet' type='text/css' media='all' />
	<title>LÖRK(SOURCE) » Administrations Værktøj</title>
	<script type='text/javascript' src='js/javascript.js'></script>

	<body>
	<div id='workarea'>
		<p>WEEEE!</p>
	</div>

	</body>
	</html>";
}
else
{
	echo "AWWWW FUCK!!! DIDN'T WORK!!!";
}
}

 

If you have any questions regarding the code, please just post them :)

 

Thanks in advance (yet again :)

 

- Kenneth Johns3n

Link to comment
https://forums.phpfreaks.com/topic/210839-problem-with-uploading-a-file/
Share on other sites

  Quote

Hi

 

You appear not to have specified  ENCTYPE="multipart/form-data"  for the form, which is required for file uploads.

 

All the best

 

Keith

 

Thank you so much! :) I feel soo dumb for forgetting that.. hehe this is solved now.. thanks again mate :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.