Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Upload

Status
Not open for further replies.

TheSponge

Technical User
Jul 2, 2003
442
GB
I want to echo back the filename and filepath once an image has been uploaded to the server?

The image upload works fine, and it echoes back "upload succesful"

can someone help? here is the bottom of my script:

// What is the files temporary name?
$file = $_FILES['userfile']['tmp_name'];

// What is the files actual name?
$filename = $_FILES['userfile']['name'];

// Does this file already exist on the server?
if(file_exists($uploaddir . $filename)) {
die("A file with that name already exists on this server.");
} else {
// This file does not already exist, so copy it.
copy($file, $uploaddir.$filename) or die("Could not copy file.");
}

// All done! :)
echo "Upload successful";
}


A+,CCNA
 
$_FILES is an array, so if you do

print $_FILES;

all PHP will output is something like:

Array()


You need to output the appropriate element of the array. The PHP online manual section titled, "Handling file uploads" has a lot of information you need to review.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
thats helpful, but whats the code??? surely its a simple echo or print statement?

A+,CCNA
 
$_FILES['userfile']['name']
The original name of the file on the client machine.

$_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on the server.


But in your code you should write

Code:
print '[URL unfurl="true"]http://www.mysite.com/uploads/'[/URL] . $filename;

gry online
 
No still doesnt work....Thanks anyway

A+,CCNA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top