Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Problem: Uploading Images

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Problem: Uploading Images

Postby alsaffar » Fri Aug 23, 2002 10:10 am

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:

Code: Select all
<?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
alsaffar
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 14, 2002 11:49 am

Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron