hisham
IS-IT--Management
- Nov 6, 2000
- 194
I tried to run the following code to upload a image file to my server but always I get the following error: Couldn't Copy File To Server.
Thanks in advance for any help.
by the way, anbody can guide me to a simple php-ftp code to do that?
----------------------------------------
the config file:
<?
$absolute_path = "/usr/local/apache/htdocs/myfolder"; //Absolute path to where files are uploaded
$size_limit = "no"; //do you want a size limit yes or no.
$limit_size = "20000000"; //How big do you want size limit to be in bytes
$limit_ext = "no"; //do you want to limit the extensions of files uploaded
$ext_count = "4"; //total number of extensions in array below
$extensions = array(".gif", ".jpg", ".jpeg", ".png" //List extensions you want files uploaded to be
?>
-----------------------------------------
the upload file:
<?php
switch($upload) {
default:
include "config.php";
echo "
<html>
<head>
<title>Upload</title>
</head>
<body>
<div>
<center>
<table border=\"0\" id=\"AutoNumber1\">
<tr>
<td>
<p><b>Upload File</b></font></td>
</tr>
<tr>
<td>The following restrictions apply:</font><ul>
<li>File extension must be <b>";
if (($extensions == "" or ($extensions == " " or ($ext_count == "0" or ($ext_count ==
"" or ($limit_ext != "yes" or ($limit_ext == "") {
echo "any extension";
} else {
$ext_count2 = $ext_count+1;
for($counter=0; $counter<$ext_count; $counter++) {
echo " $extensions[$counter]";
}
}
if (($limit_size == "" or ($size_limit != "yes") {
$limit_size = "any size";
} else {
$limit_size .= " bytes";
}
echo"</b></font></li>
<li>Maximum file size is $limit_size</li>
<li>No spaces in the filename</li>
<li>Filename cannot contain illegal characters
(/,*,\,etc)<BR>
</li>
</ul>
<form method=\"POST\" action=\"$PHP_SELF?upload=doupload\" enctype=\"multipart/form-data\">
<p align=\"center\">
<input type=file name=file size=30><br>
<br>
<button name=\"submit\" type=\"submit\">Upload</button>
</p>
</form>
<p>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>";
break;
case "doupload":
include "config.php";
$endresult = "<font size=\"2\">File Was Uploaded</font>";
if ($file_name == "" {
$endresult = "<font size=\"2\">No file selected</font>";
}else{
if(file_exists("$absolute_path/$file_name") {
$endresult = "<font size=\"2\">File Already Existed</font>";
} else {
if (($size_limit == "yes" && ($limit_size < $file_size)) {
$endresult = "<font size=\"2\">File was to big</font>";
} else {
$ext = strrchr($file_name,'.');
if (($limit_ext == "yes" && (!in_array($ext,$extensions))) {
$endresult = "<font size=\"2\">File is wrong type</font>";
}else{
@copy($file, "$absolute_path/$file_name" or $endresult = "<font size=\"2\">Couldn't Copy File To
Server</font>";
}
}
}
}
echo "
<html>
<head>
<title>Upload</title>
</head>
<body>
<div align=\"center\">
<center>
<table>
<tr>
<td>
<p align=\"center\"><b>Upload File</b></td>
</tr>
<tr>
<td>
<center> $endresult </center>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>";
break;
}
?>
Thanks in advance for any help.
by the way, anbody can guide me to a simple php-ftp code to do that?
----------------------------------------
the config file:
<?
$absolute_path = "/usr/local/apache/htdocs/myfolder"; //Absolute path to where files are uploaded
$size_limit = "no"; //do you want a size limit yes or no.
$limit_size = "20000000"; //How big do you want size limit to be in bytes
$limit_ext = "no"; //do you want to limit the extensions of files uploaded
$ext_count = "4"; //total number of extensions in array below
$extensions = array(".gif", ".jpg", ".jpeg", ".png" //List extensions you want files uploaded to be
?>
-----------------------------------------
the upload file:
<?php
switch($upload) {
default:
include "config.php";
echo "
<html>
<head>
<title>Upload</title>
</head>
<body>
<div>
<center>
<table border=\"0\" id=\"AutoNumber1\">
<tr>
<td>
<p><b>Upload File</b></font></td>
</tr>
<tr>
<td>The following restrictions apply:</font><ul>
<li>File extension must be <b>";
if (($extensions == "" or ($extensions == " " or ($ext_count == "0" or ($ext_count ==
"" or ($limit_ext != "yes" or ($limit_ext == "") {
echo "any extension";
} else {
$ext_count2 = $ext_count+1;
for($counter=0; $counter<$ext_count; $counter++) {
echo " $extensions[$counter]";
}
}
if (($limit_size == "" or ($size_limit != "yes") {
$limit_size = "any size";
} else {
$limit_size .= " bytes";
}
echo"</b></font></li>
<li>Maximum file size is $limit_size</li>
<li>No spaces in the filename</li>
<li>Filename cannot contain illegal characters
(/,*,\,etc)<BR>
</li>
</ul>
<form method=\"POST\" action=\"$PHP_SELF?upload=doupload\" enctype=\"multipart/form-data\">
<p align=\"center\">
<input type=file name=file size=30><br>
<br>
<button name=\"submit\" type=\"submit\">Upload</button>
</p>
</form>
<p>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>";
break;
case "doupload":
include "config.php";
$endresult = "<font size=\"2\">File Was Uploaded</font>";
if ($file_name == "" {
$endresult = "<font size=\"2\">No file selected</font>";
}else{
if(file_exists("$absolute_path/$file_name") {
$endresult = "<font size=\"2\">File Already Existed</font>";
} else {
if (($size_limit == "yes" && ($limit_size < $file_size)) {
$endresult = "<font size=\"2\">File was to big</font>";
} else {
$ext = strrchr($file_name,'.');
if (($limit_ext == "yes" && (!in_array($ext,$extensions))) {
$endresult = "<font size=\"2\">File is wrong type</font>";
}else{
@copy($file, "$absolute_path/$file_name" or $endresult = "<font size=\"2\">Couldn't Copy File To
Server</font>";
}
}
}
}
echo "
<html>
<head>
<title>Upload</title>
</head>
<body>
<div align=\"center\">
<center>
<table>
<tr>
<td>
<p align=\"center\"><b>Upload File</b></td>
</tr>
<tr>
<td>
<center> $endresult </center>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>";
break;
}
?>