I found a nice php script to upload files, but every time I upload an image it gets correpted when it reaches the server, see my code:
Q1. Actullay it's working But avoid the correpttion of images? Although text, php and html files are uplaoded successfuly!
Q2. I have to specify the file name, although if I only specify the path to the file in the browseer, it get uploaded successfuly, but it gave an error after that "Permission Denied" but it is uploaded correctly. How I can avoid specifying the file name?
So can u help me to get it working nicely?
BesT WiShEs
Ali
Code:
<?php
$maxsize = "200000";
$path = "/path/to/the/upload/directory/";
if($uploads <= 1)
{
$uploads = 5;
}
$fields = $uploads + $uploads;
for($n = 0; $n < $uploads; $n++)
{
if($uploadedFile[$n] != "" && $uploadedFile[$n] != "none")
{
copy("$uploadedFile[$n]", "$path$uploadedFile_name[$n]");
rename("$path$uploadedFile_name[$n]", "$path$fileName[$n]");
if(file_exists("$path$fileName[$n]"))
{
print("upload successful for $fileName[$n] - $uploadedFile_size[$n] bytes<br>\n");
}
else
{
print("error: upload failed<br>\n");
}
}
}
print("<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">\n");
print("<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$maxsize\">\n");
print("<table border=\"0\" cellpadding=\"0\" cellspacing=\"3\"><tr><td>\n");
print("<b>Name:</b></td><td>\n");
print("<b>File Location:</b></td></tr>\n");
for($i = 1; $i <= $uploads; $i++)
{
print("<tr><td><input type=\"text\" name=\"fileName[]\" size=\"13\"></td><td>\n");
print("<input type=\"file\" name=\"uploadedFile[]\" size=\"25\"></td></tr>\n");
}
print("<tr><td align=\"center\"><input type=\"submit\" value=\"UPLOAD\"></td><td>\n");
print("<a href=\"$PHP_SELF?uploads=$fields\">More Upload Fields</a></td></tr>");
print("</table>\n");
print("</form>\n");
?>
Q1. Actullay it's working But avoid the correpttion of images? Although text, php and html files are uplaoded successfuly!
Q2. I have to specify the file name, although if I only specify the path to the file in the browseer, it get uploaded successfuly, but it gave an error after that "Permission Denied" but it is uploaded correctly. How I can avoid specifying the file name?
So can u help me to get it working nicely?
BesT WiShEs
Ali