Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
My upload script sucks...
Old 06-16-2005, 06:19 PM My upload script sucks...
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Hey guys! Recently (today as it happens) I have made an upload script, for where my users can upload a picture, this picture will then be used as there display picture in the profile... Like on forums! A few things that are wrong with this are:
The file keeps original name, maybe need to change incase someone else uploads same file name but different file.
The file type; uses only pictures

Anyone know how I can resolve this?
PHP Code:
<html><head><title>XinGs Upload script</title></head></html>

<?

if(isset($submit)) {

$target_path "uploads/";
$filesize 100000;
$target_path $target_path basename$_FILES['uploadedfile']['name']);

if(
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
     echo 
"The file "basename$_FILES['uploadedfile']['name']). " has been uploaded";
     echo 
"<br>";
     echo 
"You can see your file at: <a href=\"./$target_path\">HERE</a>";
} else{
     echo 
"There was an error uploading the file, the file is possibly too large!!";
     echo 
"<br>";
     echo 
"The max file size is: $filesize kb";
}

} else {
?>

<form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="<? echo "$filesize"?>" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit"  name="submit" value="Upload File" />
</form>
<br>
View other peoples uploaded files <a href="./uploads/">here!</a>
<? 
}
?>

Last edited by feraira; 06-16-2005 at 08:33 PM..
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-17-2005, 08:37 AM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Anyone?
feraira is offline
Reply With Quote
View Public Profile
 
Old 06-17-2005, 09:44 AM
Monkeon's Avatar
Skilled Talker

Posts: 59
Trades: 0
heh heh, I'm working on the exact same thing myself right now!

The way I got around the naming thing was to do this

PHP Code:
move_uploaded_file($_FILES['image']['tmp_name'], $ImageDir.'/'.$username.'/'.$rand.'.'.jpg)
or die (
"Couldn't upload ".$_FILES['image']['name']."\n"); 
$username is just the users directory I'm uploading to and $rand is a random number.
(I decided to name my images with a random number)

So you can see, in the moving process you can specify the name of the file.
__________________

Please login or register to view this content. Registration is FREE
FREE Online Dating!
Meet your perfect match online right now!
Monkeon is offline
Reply With Quote
View Public Profile
 
Old 06-17-2005, 10:06 AM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Ok, cool might talk to ya later about it lol
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to My upload script sucks...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13547 seconds with 12 queries