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
Old 06-22-2005, 02:01 PM Image upload thing
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
OK, I need to code a PHP file that will do the following:

Let the user browse there machine for a picture (or link one);
Max file size / images size;
Make the file name the username with a number.. If I upload one: XinG01 and if I upload another XinG02 and so on...

I have the upload thing at the moment, but thats the only thing... Heres what I got:
PHP Code:
<html><head><title>XinG's 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>
<? 
}
?>
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2005, 07:19 AM
Junior Talker

Posts: 2
Trades: 0
For this sort of stuff its much easier to use a database in terms of the naming aspect as there is no way of knowing how many images a user has uploaded without recording it in a database table, then you just count the number of entries in order to get the correct filename e.g Xing01.jpg

However in order to rename the file you simply use the rename function. You can assign $newimagename any value you want but in order to do this you must first know the file extension as otherwise if they upload a .gif and you assign $newimagename to image.jpg it wont work.

rename( $target_path . $_FILES['uploadedfile']['name'], $target_path . $newimagename );

To work out the fileextension you use the following code.

$filetype = strrchr($_FILES['uploaded file']['name'],'.');

So you could then combine 2 vars $newimagename = $username . $filetype;

Hope this helps

Thanks

Richard
__________________

Please login or register to view this content. Registration is FREE
guldan is offline
Reply With Quote
View Public Profile Visit guldan's homepage!
 
Reply     « Reply to Image upload thing
 

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.18504 seconds with 12 queries