October 4, 2002
Hallå! Är inte så hemma på PHP så: vad är det för fel på det här uploadscriptet? Har försökt fixa det, men inte lyckats...
http://tobiaz.myftp.org/uploader/
Det här blir felet: http://tobiaz.myftp.org/upload.php
October 4, 2002
Mm... så långt har jag oxå fattat 😀 men tack för hjälpen...
Här är koden för upload.php:
<html>
<head><title>..:: Upload a file ::..</title>
<?php
require ('config.php'); # Include configuration file.
require ('common.php'); # Include common file with functions in.
?>
<body>
<font face="verdana" color="darkblue">
<center>
<?php
# Do not change the logo file here, there is an option for this in the config.php file.
echo "[Image Can Not Be Found]";
?>
<table>
<tr><td>Directory Listing</td></tr>
</table>
<?php
if ($show_info == "1")
{
require 'config.php';
$fileaccept = "";
if($filetype1 != "NULL")
{
$fileaccept = $fileaccept . $filetype1;
}
if($filetype2 != "NULL")
{
$fileaccept = $fileaccept . ", " . $filetype2;
}
if($filetype3 != "NULL")
{
$fileaccept = $fileaccept . ", " . $filetype3;
}
if($filetype4 != "NULL")
{
$fileaccept = $fileaccept . ", " . $filetype4;
}
if($filetype5 != "NULL")
{
$fileaccept = $fileaccept . ", " . $filetype5;
}
$upload_size = $max_file_size/1024;
print "<h6>There are maximum filesize and file type restrictions in place.</h6>";
print "<h6>Accepted file types are, $fileaccept and the maximum allowed upload size is $upload_size kilobytes (KB).</h6>";
}
?>
<form enctype="multipart/form-data" action"<?php print $PHP_SELF ?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo ($max_file_size); ?>">
<input type="file" name="fupload">
<input type="submit" value="Upload File">
</form>
</body>
</html>
Här är koden för config.php:
<?php
/* Configuration Section */
$file_dir = ""; # This is the absolute path (no trailing slash).
$file_url = ""; # Full URL to the uploaded file.
$logo_file = "http://www.efusian.co.uk/~filefusian/images/efusian.jpg"; # FileFusian logo location.
$max_file_size = "110024"; # Max File Size Setting (In Bytes).
$show_info = "1"; # Shows info on main page about file sie etc. 1 = on, 0 = off.
/* Directory Listing */
$listsize = 30; # Maximum Number oF Files To Be Returned.
/* Upload Function */
# The following section allows upto 5 file types to be specified easily at startup without delving into the code of FileFusian to much.
# It is of paramount importance that something is filled in each of these filetypes or someone will be able to remove the extension from
# the file they are uploading and get past these checks.
# If you only want a certain ammount of file types, eg 3, then fill the rest in with the word NULL as the FileFusian code will not list this on the main page.
$filetype1 = ".jpg";
$filetype2 = ".gif";
$filetype3 = "NULL";
$filetype4 = "NULL";
$filetype5 = "NULL";
?>
Och för common.php:
<?php
/* Upload Routine */
if(isset($fupload))
{
require 'config.php';
$ext = strrchr($fupload_name,'.');
if ($ext == $filetype1 || $ext == $filetype2 || $ext == $filetype3 || $ext == $filetype4 || $ext == $filetype5)
{
/* Peform Upload Actions */
$final_path=$file_dir . "/" . $fupload_name; # Generate final path & filename.
move_uploaded_file( $fupload, $final_path ) or die ("Unable To Copy"); # Moves file.
/* Perform Post Upload Actions */
upload_report($fupload, $fupload_name, $fupload_size, $fupload_type, $file_url, $file); # Call upload report generation function.
}
else
{
echo '<script language="JavaScript">';
echo 'error = window.open("error.php?id=filetype","","width=350,height=235,status=no,toolbar=no,menubar=no");';
echo '</script>';
}
}
?>
<?php
/* Upload Report Generation Function */
function upload_report($fupload, $fupload_name, $fupload_size, $fupload_type, $file_url, $file)
{
/* Generate Upload Report */
require('config.php');
echo '<font face="verdana" color="darkblue">';
echo "[Image Can Not Be Found]";
Print "<h3>Upload Report</h3>";
echo '</font>';
print "Path: $fupload
";
print "Name: $fupload_name
";
print "Size: $fupload_size bytes
";
print "Type: $fupload_type
";
print "Uploaded File: $fupload_name
";
print "Destination: $file_dir/$fupload_name
";
}
?>
<?php
/* Directory Listing Function */
function directory_listing($file_dir, $file_url)
{
require('config.php'); # Reads in configuration file.
$directory = opendir ($file_dir); # Open Directory for reading.
echo '<div class = "container">'; # Use CSS Class (container).
echo '<font face="verdana" color="darkblue">'; # Sets font face & color.
echo "[Image Can Not Be Found]"; # Display FileFusian logo.
echo '<div class = "header">'; # Use CSS class (header).
echo '<h3>Directory Listing</h3>'; # Display file listing page title.
echo '</div>'; # End CSS class (header).
print "<h6>A maximum of $listsize files will be displayed.</h6>"; # Displays number of files to be displayed.
print "<hr>"; # Displays horizontal rule.
echo '<table>'; # Create table.
for($fcount = 0; $fcount < $listsize; $fcount++) # File display loop - runs until $listsize value is reached.
{
$file = readdir ($directory);
echo '<tr><td>'; # Create table row, get ready for data.
if($file != "" && $file != "." && $file != "..")
{
echo '[Image Can Not Be Found]'; # Link to download icon.
print " $file"; # Prints filename hyperlink to directory listing.
}
echo '</td></tr>'; # Close table data and row.
}
echo '</table>'; # Close table.
echo '</div>'; # End CSS class (container).
closedir ($directory); # Close directory.
}
?>
Förstår inte riktigt vad funktionen PHP_SELF gör för något, alltså den hänvisar ju till sig själv, men vad ska den ha för funktion? 🙄
November 1, 2002
Det har att göra med hur PHP är konfigurerat. Ditt script är antagligen skrivet för PHP3 medan du kör PHP4 på servern. I PHP3 är register globals aktiverat som standard, i PHP4 är det vanligen inte aktiverat. Det betyder att informationen i PHPs globala associativa arrayer ($_SERVER, $_POST o.s.v.) finns tillgänglig i två former i PHP3. $HTTP_SERVER_VARS[PHP_SELF] är samma sak som $PHP_SELF. Det gäller inte i PHP4. Dessutom har $HTTP_SERVER_VARS bytt namn till $_SERVER iom PHP4.
Lösningen är att använda funktionen extract() som tar en associativ array som argument och skapar variabler av nycklarna.
Lägg till följande i t.ex. common.php
extract($_SERVER);
extract($_POST);
extract($_GET);
extract($_COOKIE);
extract($_SESSION);
extract($_ENV);
extract($_FILES);
November 1, 2002
För att aktivera register globals går du in i PHP.INI och letar upp raden
register globals = Off
och ändrar Off till On.
För att stänga av begränsning av filstorlek i scriptet kan du lägga på några nollor på filstorleken på raden
$max_file_size = "110024";
i config.php.
Om du vill att alla filtyper ska tillåtas kan du göra följande ändring i common.php:
if ($ext == $filetype1 || $ext == $filetype2 || $ext == $filetype3 || $ext == $filetype4 || $ext == $filetype5)
ändras till
if (true)
October 4, 2002
Hmm... nu är det bara det här felmeddelandet kvar =/
Dock har jag ändrat i filerna men får jag bara lilte vägledning så... 😀
Notice: Array to string conversion in common.php on line 45
Unable To Copy
Edit: Hmm... ska nog sova nu... skola om några dar... men skriv ni så kollar jag (och tackar er jättemycket) imorrn 😀
Sov gott alla på NH! :worshipp:
October 4, 2002
Ok jag har ett enklare script nu...
Får ett par felmeddelanden som har med variabeln $ADMIN att göra (tror jag iaf :D)
här är setup.php:
<?php
///////////////////////////////////////////////
// //
// Uploader v.1.1 //
// ----------------------------------------- //
// by Graeme (webmaster@phpscriptcenter.com) //
// http://www.phpscriptcenter.com //
// //////////////////////////////
// PHP Script CENTER offers no warranties on this script. //
// The owner/licensee of the script is solely responsible for any //
// problems caused by installation of the script or use of the script //
// //
// All copyright notices regarding Uploader, must remain //
// intact on the scripts and in the HTML for the scripts. //
// //
// (c) Copyright 2001 PHP Script CENTER //
// //
// For more info on Uploader, //
// see http://www.phpscriptcenter.com/uploader.php //
// //
///////////////////////////////////////////////////////////////////////////
$ADMIN[RequirePass] = "No"; // Checks to see if upload has a vaild password
$ADMIN[Password] = "password"; // This is the password if the above option is Yes
$ADMIN[UploadNum] = "10"; // Number of upload feilds to put on the html page
$ADMIN[directory] = "uploads"; // The directory the files will be uploaded to (must be chmoded to 777)
?>
och här är upload.php:
<HTML>
<HEAD>
<TITLE>..:: Upload A File ::..</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<!--
// Powered by: Uploader Version 1.1 (http://www.phpscriptcenter.com/upload.php)
-->
<?php
///////////////////////////////////////////////
// //
// Uploader v.1.1 //
// ----------------------------------------- //
// by Graeme (webmaster@phpscriptcenter.com) //
// http://www.phpscriptcenter.com //
// //////////////////////////////
// PHP Script CENTER offers no warranties on this script. //
// The owner/licensee of the script is solely responsible for any //
// problems caused by installation of the script or use of the script //
// //
// All copyright notices regarding Uploader, must remain //
// intact on the scripts and in the HTML for the scripts. //
// //
// (c) Copyright 2001 PHP Script CENTER //
// //
// For more info on Uploader, //
// see http://www.phpscriptcenter.com/upload.php //
// //
///////////////////////////////////////////////////////////////////////////
require("setup.php");
if($doupload) {
if($ADMIN[RequirePass] == "Yes") {
if($password != "$ADMIN[Password]") {
?>
<CENTER><FONT FACE="Verdana">Error</FONT></CENTER></P>
<CENTER><TABLE WIDTH="450" BORDER="0" CELLSPACING="0"
CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#000000">
<TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD COLSPAN="2" BGCOLOR="#ffffff">
<FONT COLOR="#000000" SIZE="-1" FACE="Verdana">Invalid Password</FONT></TD>
</TR>
</TABLE></TD>
</TR>
</TABLE></CENTER></P>
<CENTER></CENTER></P>
<CENTER></CENTER></P>
<CENTER><FONT SIZE="-2" FACE="Verdana">Powered by: Uploader Version 1.1</FONT></CENTER>
</BODY>
</HTML>
<?php
exit();
}
}
$num = 0;
while($num < $ADMIN[UploadNum]) {
$num++;
$picture = "fileup$num"."_name";
$picture1 = $$picture;
$picture2 = "fileup$num";
$picture3 = $$picture2;
if($picture3 != "none") {
$filesizebtyes = filesize($picture3);
$ok = 1;
if($filesizebtyes < 10) {
$error .= "Error uploading (file size lower than 10 bytes) for file $num
";
$ok = 2;
}
if(file_exists("$ADMIN[directory]/$picture1") OR $ok == 2) {
$error .="File name already exists for file $num
";
} else {
copy ($picture3, "$ADMIN[directory]/$picture1");
$error .="File $num has been uploaded
";
}
}
}
if(!$error) {
$error .= "No files have been selected for upload";
}
?>
<CENTER><FONT FACE="Verdana">Status</FONT></CENTER></P>
<CENTER><TABLE WIDTH="450" BORDER="0" CELLSPACING="0"
CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#000000">
<TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD COLSPAN="2" BGCOLOR="#ffffff">
<FONT COLOR="#000000" SIZE="-1" FACE="Verdana"><?php echo $error; ?></FONT></TD>
</TR>
</TABLE></TD>
</TR>
</TABLE></CENTER></P>
<CENTER></CENTER></P>
<CENTER></CENTER></P>
<CENTER><FONT SIZE="-2" FACE="Verdana"></FONT></CENTER>
</BODY>
</HTML>
<?php
exit();
} else {
$num = 0;
while($num < $ADMIN[UploadNum]) {
$num++;
$html .= "<TR>
<TD WIDTH="25%" BGCOLOR="#295e85">
<FONT COLOR="#ffffff" SIZE="-1" FACE="Verdana">File $num:</FONT></TD>
<TD WIDTH="75%" BGCOLOR="#ffffff">
<INPUT NAME="fileup$num" TYPE="file" SIZE="25">
</TD> ";
}
?>
<FORM ENCTYPE="multipart/form-data" ACTION="upload.php" METHOD="POST">
<CENTER><FONT FACE="Verdana">Ladda upp</FONT></CENTER></P>
<CENTER><TABLE WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#000000">
<TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD COLSPAN="2" BGCOLOR="#295e85">
<FONT COLOR="#ffffff" SIZE="-1" FACE="Verdana">Välj filer</FONT></TD>
</TR><?php echo $html; ?>
</TABLE></TD>
</TR>
</TABLE></CENTER></P>
<?php
if($ADMIN[RequirePass] == "Yes") {
?>
<CENTER><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#000000">
<TABLE WIDTH="300" BORDER="0" CELLSPACING="1" CELLPADDING="2">
<TR>
<TD WIDTH="33%" BGCOLOR="#295e85">
<FONT COLOR="#ffffff" SIZE="-1" FACE="Verdana">Password:</FONT></TD>
<TD WIDTH="67%" BGCOLOR="#ffffff">
<INPUT NAME="password" TYPE="password" SIZE="25">
</TD>
</TR>
</TABLE></TD>
</TR>
</TABLE></CENTER></P>
<?php
}
?>
<CENTER><INPUT NAME="doupload" TYPE="submit" VALUE="Ladda upp filer"></CENTER></FORM>
<CENTER></CENTER></P>
<CENTER></CENTER></P>
<CENTER><FONT SIZE="-2" FACE="Verdana">Powered by: Uploader Version 1.1</FONT></CENTER>
</BODY>
</HTML>
<?php
exit();
}
?>
Tacksam för lite hjälp 😀
Här är felmeddelandena som jag får: http://tobiaz.myftp.org/upload.php
January 21, 2002
Jag testade det scriptet och det är inga problem att ladda upp filer för mig. Är det verkligen samma filer du använder som du postade här? Jag ser att du får error på bl.a. rad rad 25 i setup.php medans den fil du postade bara är på 4 rader...
Även de error jag ser att du får i upload.php verkar missstämma mot den fil jag har.
2 Guest(s)