Morthian Posted April 16, 2007 Share Posted April 16, 2007 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 More sharing options...
Demonic Posted April 16, 2007 Share Posted April 16, 2007 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. Link to comment https://forums.phpfreaks.com/topic/47181-help-with-upload-script/#findComment-230078 Share on other sites More sharing options...
Morthian Posted April 16, 2007 Author Share Posted April 16, 2007 Yeah, I don't know what the hell I was thinking there. Thanks for pointing that out. But I still don't understand why my Switch event is not working. The game_ext variable never gets set to either of those options. Link to comment https://forums.phpfreaks.com/topic/47181-help-with-upload-script/#findComment-230097 Share on other sites More sharing options...
cyrixware Posted April 16, 2007 Share Posted April 16, 2007 Is ther any options to select inorder to perfrom your switch statements? And try to change the location of the switch statements in the upper part of the if statement. Link to comment https://forums.phpfreaks.com/topic/47181-help-with-upload-script/#findComment-230184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.