Jump to content

Uploading lots at once


Pezmc

Recommended Posts

Basicly if ($_get["do"] == "add") { this function is called to upload a swf file and a jpg file, these files are places in swf and logos respectively. Each of these files should be named with the game name set in the html form but with no spaces (using str_replace(" ", "", $temp);).

The jpg file is then dealt with using thumbnail_generator.php (a function to resize a image, the call is in this format $oldname,$newname,$width,$height.

However none of this works, I have tried debugging and have simplified alot of stuff but it still does not work, why?

 

function add() {
if(isset($_POST["submit"])) {
        extract($_POST);
        $errors = 0;
        $errorlist = "";
	if ($name == "") { $errors++; $errorlist .= "A game name is required.<br />"; }
	if ($description == "") { $errors++; $errorlist .= "A description is required.<br />"; }
	if (strlen($description) < 20) { $errors++; $errorlist .= "The description must be at least twenty letters long.<br />"; }
	if ($howtoplay == "") { $errors++; $errorlist .= "A how to play is required.<br />"; }
	if (strlen($howtoplay) < 20) { $errors++; $errorlist .= "The how to play must be at least twenty letters long.<br />"; }
	if (!is_numeric($width)) { $errors++; $errorlist .= "The width must be a number.<br />"; }
	if (!is_numeric($height)) { $errors++; $errorlist .= "The height must be a number.<br />"; }
	if ($width == "") { $errors++; $errorlist .= "The swf width is required.<br />"; }
	if ($height == "") { $errors++; $errorlist .= "The swf height is required.<br />"; }
	if ($name == "") { $errors++; $errorlist .= "A game name is required.<br />"; }	

if ($errors != 0) { echo "We encountered some problems, see below:<br>$errorlist"; die(); }

$uploaddir = '/home/.penda/pezmc/games.pezmc.com/swf/';
$uploadfile = $uploaddir . basename($_FILES['swf']['name']);
move_uploaded_file($_FILES['swf']['tmp_name'], $uploadfile);

$uploaddir = '/home/.penda/pezmc/games.pezmc.com/logos/';
$uploadfile = $uploaddir . basename($_FILES['logo']['name']);
move_uploaded_file($_FILES['swf']['tmp_name'], $uploadfile);

$shortname = str_replace(" ","", $name);
$swf = "swf/";
$swf .= basename($_FILES['swf']['name']);
$logo = "logos/";
$logo .= basename($_FILES['logo']['name']);

include("thumbnail_generator.php");

createthumb($logo,"$shortnamesmall.jpg","20","20");
createthumb($logo,"$shortname.jpg","80","80");
createthumb($logo,"$shortnamebig.jpg","300","300");

echo "Hey it all worked, <a href=\"admin.php\">Back</a>";
echo "<br>Debug";
echo $_FILES['logo']['tmp_name'];
echo "<br>";
echo $_FILES['swf']['tmp_name'];
die();

} else {
echo "<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype=\"multipart/form-data\" action=\"admin.php?do=add\" method=\"POST\">
    <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1048576\" />
Game Name: <input name=\"name\" type=\"text\" /><br />
Description: <textarea name=\"description\" cols=\"50\" rows=\"5\"></textarea>
<br />
How to play: <textarea name=\"howtoplay\" cols=\"50\" rows=\"5\"></textarea>
<br />
Swf file: <input name=\"swf\" type=\"file\" /><br />
Width: <input name=\"width\" type=\"text\" size=\"5\" />
<br />
Height: <input name=\"height\" type=\"text\" size=\"5\" />
<br />
Rating: <select name=\"rating\">
  <option value=\"1\">1</option>
  <option value=\"2\">2</option>
  <option value=\"3\">3</option>
  <option value=\"4\">4</option>
  <option value=\"5\">5</option>
  <option value=\"6\">6</option>
  <option value=\"7\">7</option>
  <option value=\"8\">8</option>
  <option value=\"9\">9</option>
  <option value=\"10\">10</option>
</select><br />
    Logo 500x500 Jpg: <input name=\"logo\" type=\"file\" /><br />
    

    <input type=\"submit\" name=\"submit\" value=\"Send File\" />
</form>";
	}

 

All people that help will receive a free link on the thanks page of my website.

Link to comment
Share on other sites

i got a upload code, see if you make sense of this, u can edit it itno your own

 

<?php 

echo('Upload image<br><br>');


$path = "uploads/"; 

$max_size = 5000000; 



if (!isset($HTTP_POST_FILES['userfile'])) exit; 



if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 



if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>"; exit; } 

if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 



if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists, try calling it a different name.<br>"; exit; } 



$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path . 

$HTTP_POST_FILES['userfile']['name']); 

if (!$res) { echo "upload failed!<br>"; exit; } else { echo "upload sucessful<br><br>"; } 



echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>"; 
echo "File Path: <a href=uploads/".$HTTP_POST_FILES['userfile']['name']." TARGET=_BLANK>uploads/".$HTTP_POST_FILES['userfile']['name']."</a><br>"; 
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>"; 
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>"; 
echo "<img src=uploads/".$HTTP_POST_FILES['userfile']['name']." width=200 height=250><br>";
include("cons.php"); 
$avatar2 = "";   
mysql_query("UPDATE `users` SET `avatar` = 'uploads/".$HTTP_POST_FILES['userfile']['name']."' WHERE `username` = '$user';");
echo "Profile Pic updated";
} else { echo "Wrong file type<br>"; exit; } 

} 



$my_file = $HTTP_POST_FILES['userfile']['name'];


?> 

 

this is very simple, should work

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.