Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Pages: [1]
Send this topic | Print
Topic: uploading script help  (Read 3290 times)
« on: October 30, 2005, 11:57:58 PM »
multippt Offline
Newbie

View Profile
*
Posts: 2



I have tried multiple scripts on the internet but I can't get any of them working.

<?php
// Upload settings
$folder = "uploads/"; // Folder in which to store files
$maxlimit = 1000000; // Set maximum file limit (in bits)
$allowed_ext = "jpg,gif,png,jpeg"; // Set allowed extensions (split using comma)
$overwrite = "yes"; // Allow file overwrite? yes/no

$match = ""; // Clear match variable; for security purposes
$filesize = $_FILES['userfile']['size']; // Get file size (in bits)
$filename = strtolower($_FILES['userfile']['name']); // Get file name; make it all lowercase

if(!$filename || $filename==""){ // File not selected
   $error = "- No file selected for upload.";
}elseif(file_exists($folder.$filename) && $overwrite=="no"){ // Check if file exists
   $error = "- File already exists: $filename";
}

// Check if file size
if($filesize < 1){ // File is empty
   $error .= "- File size is empty.";
}elseif($filesize > $maxlimit){ // File is more than maximum
   $error .= "- File size is too big.";
}

$file_ext = preg_split("/./",$filename); // Split filename at period (name.ext)
$allowed_ext = preg_split("/,/",$allowed_ext); // Create array of extensions
foreach($allowed_ext as $ext){
   if($ext==$file_ext[1]) $match = "1"; // File is allowed
}

// File extension not allowed
if(!$match){
   $error .= "- File type isn't allowed: $filename";
}

if($error){
   print "Error trying to upload file: $error"; // Display error messages
}else{
   if(move_uploaded_file($_FILES['userfile']['tmp_name'], $folder.$filename)){ // Upload file
      print "Success! The file has been uploaded: $filename";
   }else{
      print "Error! File size might exceed upload limit of server. Try again."; // Display error
   }
}

?>

^uploader.php

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Page 3</title>
</head>

<body>

<form enctype="multipart/form-data" method="post" action="up.php">
Select file: <input type="file" name="userfile">
<input type="submit" value="Upload">
</form>

</body>

</html>

^loader.htm

any help would be appreciated.
Report to moderator   Logged

 
« Reply #1 on: January 14, 2006, 04:43:52 PM »
Do you practice what you preach?
cool1.t35.com Offline
Member

View Profile WWW
***
Posts: 161



php is in safe mode make sure nothing you do makes your script blocked.  grin
Report to moderator   Logged

The Light can never overpower the darkness alone. Love is needed.

Islam is peace.

http://www.islamhope.net
« Reply #2 on: January 18, 2006, 08:10:00 PM »
T35 Head Forum Administrator
dWhite Offline
Administrator
Sr. Member

View Profile WWW
*****
Posts: 295



If I can remember correctly, T35 blocked the uploading via php scripts since it could cause extreme abuse.
Report to moderator   Logged

Daniel White,
T35 Head Forum Administrator

Free Flash Arcade Games | Arcade Blog
« Reply #3 on: February 23, 2006, 05:09:45 PM »
bile Offline
Jr. Member

View Profile WWW
**
Posts: 70



This script will allow you to upload a multiple number of images
Code:
<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" /><br />
<input type="file" name="pictures[]" /><br />
<input type="file" name="pictures[]" /><br />
<input type="submit" value="Send" />
</p>
</form>

<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
   if (
$error == UPLOAD_ERR_OK) {
       
$tmp_name $_FILES["pictures"]["tmp_name"][$key];
       
$name $_FILES["pictures"]["name"][$key];
       
move_uploaded_file($tmp_name"/location/to/uload/$name");
   }
}
?>
Change this /location/to/uload/ to the location you want the files to upload to.
Uploading is disbled on free accounts
Report to moderator   Logged


Browser :: Mozilla FireFox 1.5
Resolution :: 1152x864
Internet Connection :: 2MB Cable Modem
« Reply #4 on: December 15, 2007, 04:25:39 AM »
hence Offline
Newbie

View Profile WWW
*
Posts: 11



Don't forget to change file permission in folder upload.
Report to moderator   Logged

« Reply #5 on: February 01, 2008, 07:59:38 AM »
dundun Offline
Newbie

View Profile
*
Posts: 2



I have tried multiple scripts on the internet but I can't get any of them working.

<?php
// Upload settings
$folder = "uploads/"; // Folder in which to store files
$maxlimit = 1000000; // Set maximum file limit (in bits)
$allowed_ext = "jpg,gif,png,jpeg"; // Set allowed extensions (split using comma)
$overwrite = "yes"; // Allow file overwrite? yes/no

$match = ""; // Clear match variable; for security purposes
$filesize = $_FILES['userfile']['size']; // Get file size (in bits)
$filename = strtolower($_FILES['userfile']['name']); // Get file name; make it all lowercase

if(!$filename || $filename==""){ // File not selected
   $error = "- No file selected for upload.";
}elseif(file_exists($folder.$filename) && $overwrite=="no"){ // Check if file exists
   $error = "- File already exists: $filename";
}

// Check if file size
if($filesize < 1){ // File is empty
   $error .= "- File size is empty.";
}elseif($filesize > $maxlimit){ // File is more than maximum
   $error .= "- File size is too big.";
}

$file_ext = preg_split("/./",$filename); // Split filename at period (name.ext)
$allowed_ext = preg_split("/,/",$allowed_ext); // Create array of extensions
foreach($allowed_ext as $ext){
   if($ext==$file_ext[1]) $match = "1"; // File is allowed
}

// File extension not allowed
if(!$match){
   $error .= "- File type isn't allowed: $filename";
}

if($error){
   print "Error trying to upload file: $error"; // Display error messages
}else{
   if(move_uploaded_file($_FILES['userfile']['tmp_name'], $folder.$filename)){ // Upload file
      print "Success! The file has been uploaded: $filename";
   }else{
      print "Error! File size might exceed upload limit of server. Try again."; // Display error
   }
}

?>

^uploader.php

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Page 3</title>
</head>

<body>

<form enctype="multipart/form-data" method="post" action="up.php">
Select file: <input type="file" name="userfile">
<input type="submit" value="Upload">
</form>

</body>

</html>

^loader.htm

any help would be appreciated.

On most web hosts the maximum upload filesize (set in a file called php.ini) is set to 2MB. If your maximum filesize is greater than this limit, you're not allowed to upload. Smiley
Report to moderator   Logged
 
Pages: [1]
Send this topic | Print
Jump to:  

Powered by SMF | SMF © 2006-2008, Simple Machines LLC