Jump to content

Help with upload script


Morthian

Recommended Posts

I am so amazingly flustered. I just can't seem to figure out how to make my upload script work.

 

The game_ext variable doesn't seem to set itself and I keep getting this error:

 

Warning: move_uploaded_file(upload/) [function.move-uploaded-file]: failed to open stream

 

<?php
mysql_connect('localhost', 'angryclo_user', '********') or die(mysql_error());

mysql_select_db('angryclo_angrycloud') or die(mysql_error());
  
{
if (($_FILES["game_source"]["type"] != "application/x-shockwave-flash")
&& ($_FILES["game_source"]["type"] != "application/x-cnc"))
	{
	die("Invalid file type." . "<br />");
	}

if ($_FILES["game_source"]["size"] > 500000)
	{
	die("File is too large." . "<br />");
	}

if ($_FILES["game_source"]["error"] > 0)
	{
	die($_FILES["game_source"]["error"] . "<br />");
	}
  
else
	{
	echo "Upload: " . $_FILES["game_source"]["name"] . "<br />";
	echo "Type: " . $_FILES["game_source"]["type"] . "<br />";
	echo "Size: " . ($_FILES["game_source"]["size"] / 1024) . " Kb<br />";
	echo "Temp file: " . $_FILES["game_source"]["tmp_name"] . "<br />";
	}

switch($_FILES["game_source"]["type"])
	{
	case '"application/x-shockwave-flash"':
		$game_ext=".swf";
		break;
	case '"application/x-cnc"':
		$game_ext=".ccn";
		break;
	}
}

mysql_query("INSERT INTO game_data (type, game_source, width, height, title, website_name, website_url, genre, comment)
VALUES
('".$_POST['type']."','".(mysql_insert_id().$_POST['game_ext'])."','".$_POST['width']."','".$_POST['height']."','".$_POST['title']."','".$_POST['website_name']."','".$_POST['website_url']."','".$_POST['genre']."','".$_POST['comment']."')")
or die(mysql_error());

move_uploaded_file($_FILES["game_source"]["tmp_name"],
"upload/" . $_FILES["game_source"][(mysql_insert_id().$game_ext)]);

echo "Stored in: " . "upload/" . $_FILES["game_source"][(mysql_insert_id().$game_ext)] . "<br />";
  
echo "Upload successful.";

mysql_close
?>

Link to comment
https://forums.phpfreaks.com/topic/47181-help-with-upload-script/
Share on other sites

try replace this:

 

move_uploaded_file($_FILES["game_source"]["tmp_name"],

"upload/" . $_FILES["game_source"][(mysql_insert_id().$game_ext)]);

 

with:


move_uploaded_file($_FILES["game_source"]["tmp_name"],
"upload/" . $_FILES["game_source"]['name']);

 

Note if you want to rename your file you need to use rename().

 

Regards,

Lamonte.

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.