•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,015 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,526 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2009 | Replies: 2
![]() |
•
•
Join Date: Jul 2006
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
Hi,
I have problem with uploading images by php script.
I created a HTML form for user to input image file, and simple PHP script which accepts this file from form and prints it in the browser. My script uploads file, prints file's name, generates HTML code, but does not output image.
My PHP code is:
[php]
<?php
$tmp_file=$_FILES['userfile']['tmp_name']; //file stored on server
if (is_uploaded_file($tmp_file)) { // check if image is uploaded by client
$size = getimagesize($tmp_file); // get image dimensions
if ($size==false) {
echo 'File $tmp_name is not accessible or it is not a valid picture';
}
else {
$width = round($size[0]);
$height = round($size[1]);
echo "<br><br>File: ", $tmp_file, "<br><br>"; // print image
echo '<img scr="'.$tmp_file.'" border="0" alt="'.$tmp_file.'" width="'.$width.'" height="'.$height.'">' ;
}
}
else { // file upload failed
echo "Possible file upload attack: ";
echo "filename '". $tmp_file . "'.";
}
}
?>
[/php]
The possible output is:
[html]
File: C:/Program Files/wamp/tmp\php4B.tmp
<IMG height=180 alt="C:/Program Files/wamp/tmp\php4B.tmp" width=300 border=0 scr="C:/Program Files/wamp/tmp\php4B.tmp">
[/html]
Instead image, it displays default icon.
That means that image file hasn't been uploaded.
What's wrong with my program? Please help me
I have problem with uploading images by php script.
I created a HTML form for user to input image file, and simple PHP script which accepts this file from form and prints it in the browser. My script uploads file, prints file's name, generates HTML code, but does not output image.
My PHP code is:
[php]
<?php
$tmp_file=$_FILES['userfile']['tmp_name']; //file stored on server
if (is_uploaded_file($tmp_file)) { // check if image is uploaded by client
$size = getimagesize($tmp_file); // get image dimensions
if ($size==false) {
echo 'File $tmp_name is not accessible or it is not a valid picture';
}
else {
$width = round($size[0]);
$height = round($size[1]);
echo "<br><br>File: ", $tmp_file, "<br><br>"; // print image
echo '<img scr="'.$tmp_file.'" border="0" alt="'.$tmp_file.'" width="'.$width.'" height="'.$height.'">' ;
}
}
else { // file upload failed
echo "Possible file upload attack: ";
echo "filename '". $tmp_file . "'.";
}
}
?>
[/php]
The possible output is:
[html]
File: C:/Program Files/wamp/tmp\php4B.tmp
<IMG height=180 alt="C:/Program Files/wamp/tmp\php4B.tmp" width=300 border=0 scr="C:/Program Files/wamp/tmp\php4B.tmp">
[/html]
Instead image, it displays default icon.
That means that image file hasn't been uploaded.
What's wrong with my program? Please help me
•
•
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation:
Rep Power: 4
Solved Threads: 6
You need to use move_uploaded_file function to transfer the image from your harddisk (temporary storage site) into a web server (which it can be your localhost or a online hosting). Check php.net for more info.
Last edited by zippee : Jul 19th, 2006 at 6:13 pm.
Ecommerce-Web-Store.com Building Your e-Business.
•
•
Join Date: Jul 2006
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
Originally Posted by zippee
You need to use move_uploaded_file function to transfer the image from your harddisk (temporary storage site) into a web server (which it can be your localhost or a online hosting). Check php.net for more info.
Thanks Zippee,
I use move_uploaded_file() and it does the job perfectly.
is_uploaded_file() automatically creates directory with the name like C:/Program Files/wamp/tmp\phpB.tmp, which doesn't seem to be a valid path name (because of ' /tmp\ ') at all. No tmp directory is really created on harddisk.
I'm still trying to understand why my code doesn't work
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- File Upload Help (PHP)
- Need file upload code for word Doc (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: <script language=\"javascript\"> Display problem with PHP & MYSQL
- Next Thread: multi dimensional array search xml parser


Linear Mode