Need help with php file upload script
Moderator: General Moderators
Need help with php file upload script
hey everyone, im kind of new to php and i have a file upload forum for my site but ive been haveing problems with it and i was wondering if anyone here had a good one to offer me. i need one that will allow you to edit the file size and file type and when it is done uploading give you the link to the file. the one that i have dose all of this its just been giving me many problems. please help me. if i posted this in the wrong section please move it. thank you
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You might want to search a http://phpclasses.org.
There was discussion recently about one, you could check with the member who posted the code:
viewtopic.php?t=65500
There was discussion recently about one, you could check with the member who posted the code:
viewtopic.php?t=65500
(#10850)
Jcart | Please use
The part of the code that im having problems is this part below because this part is hidden until the file is uploaded and once it is finished uploading it loads this code but it screws up the way the site looks until after it is uploaded you can see what im talking about here http://www.givememytones.com/upload/
thanks
Jcart | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks for the reply but i couldnt use any of the information you provided instead i would rather try to edit the script i am using.
here is the code that i am using rite now can anyone help me.Code: Select all
<?
//set these variables-----------------------------------------------------------------
$path = "~off/images/"; //path to your targetfolder after your domain
$max_size = 5900000 ; //maximum filesize
//optionally
$domain = $_SERVER["HTTP_HOST"]; //your domainname - change if necessary like "www.wza.be"
//------------------------------------------------------------------------------------
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
</div>
<FORM ENCTYPE="multipart/form-data" ACTION="index.php" METHOD="POST">
<div align="center">
<p>
<INPUT TYPE="file" NAME="userfile">
<INPUT TYPE="submit" VALUE="Upload">
<br>
<br>
</p>
</div>
</FORM>
<?
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 "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="audio/mpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="audio/x-wav") || ($HTTP_POST_FILES['userfile']['type']=="video/mpeg") || ($HTTP_POST_FILES['userfile']['type']=="video/x-msvideo") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {
if (file_exists("../".$path . $HTTP_POST_FILES['userfile']['name'])) {
echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$path .$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else {
?>
align="center">Direct link: <strong><font color="#990000"><a href="http://<? echo $domain; ?>/<? echo "../".$path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
http://<? echo $domain; ?>/<? echo $path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?><br>
</a></font></strong><br>
<br>
<?
}
echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>";
echo "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
echo "</font>";
echo "<br><br><img src=\"http://".$domain."/".$path.$HTTP_POST_FILES['userfile']['name']."\">";
} else { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"> File type not accepted</font><br>\n"; exit; }
}
?>
</body>
</html>Code: Select all
<?
}
echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>";
echo "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
echo "</font>";
echo "<br><br><img src=\"http://".$domain."/".$path.$HTTP_POST_FILES['userfile']['name']."\">";
} else { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"> File type not accepted</font><br>\n"; exit; }
}
?>Jcart | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]