By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,342 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,342 IT Pros & Developers. It's quick & easy.

Image upload problem

P: 5
Hello everybody,

Im a beginner in PHP and i'm thinking how i can make more things on my own made upload script:

Sorry if this is the wrong forum or if its not allowed to ask for script help/reqeusts.

[PHP]
<?php
if (isset($_POST['uploadedfile'])) {
if($_POST['uploadedfile'] == NULL) {
die();
}
$target_path = "images/profiles/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=profile.msnw?epuid=$regcookie\">";
} else{
echo "There was an error uploading the file, please try again!";
}

} else {
echo "
<font color=\"#064f84\" face=\"Tahoma\" size=\"2\"><b>Profile photo</b></font>
<br>
<br>
<span class=\"style10\">
<font face=\"Tahoma\" size=\"2\">
Upload your own photo to your profile, Click on browse, Select your photo and press Upload!</b>
<br><br>
<form enctype=\"multipart/form-data\" method=\"POST\" action=\"$PHP_SELF?action=dpphots\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\" />
Choose a image to upload: <input name=\"uploadedfile\" type=\"file\" /><br /><br />
<input type=\"submit\" value=\"Upload File\" />
</form></font>
</span>
";
}
?>
[/PHP]

How can i add like file types and size limits, and reondom usernames. btw, this script is not working, Im just a beginner who wants to learn and get help.

Thanks in advance.
Mar 22 '07 #1
Share this Question
Share on Google+
1 Reply

ak1dnar
Expert 100+
P: 1,584
Try this script. I couldn't figure out the File size limit. try to do it later.

[PHP]<?php
$target_path = "1234/"; //Directory Name to Upload
if($_POST['upload'])
{
$newName = md5(basename($_FILES['upload_fle']['name']));
$ext = strrchr(basename($_FILES['upload_fle']['name']), ".");
$fullName = $newName.$ext;

if(move_uploaded_file($_FILES['upload_fle']['tmp_name'], $target_path.$fullName))
{
echo "The file ". basename( $_FILES['upload_fle']['name']).
" has been uploaded with this name : ".$fullName;
} else
{
echo "There was an error uploading the file, please try again!";
}

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<? echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum">
<input name="upload_fle" type="file" id="upload_fle"/>
<BR>
<input name="upload" type="submit" value="Upload">
</form>
</body>
</html>
[/PHP]
Mar 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.