Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 2nd, 2006, 12:52 AM
Registered User
 
Join Date: Dec 2005
Location: New Delhi, New Delhi, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spbharti
Default Image Upload

I have written a code for image upload this works fine on windows machine, but when i upload it to my online server which is hosted on linux machine file is not uploaded. I am not able to find the problem.
I have given the write permission to all to that folder, but still not working.

<?php
function upload_form()
{
?>
<table border="1" align="center">
<tr><td>
<form method="post" enctype="multipart/form-data" action="<? echo $_SERVER['PHP_SELF']; ?>">
Upload File!
<input type="file" name="userfile">
<input type="submit" name="action" value="upload">
</form>
</td></tr>
</table>
<?php
}
function upload_file() {
$archive_dir="http://domain_name/images/booksimage/thumb";
$userfile_name=$_FILES['userfile']['name'];
$userfile_tmp_name=$_FILES['userfile']['tmp_name'];
$userfile_size=$_FILES['userfile']['size'];
$userfile_type=$_FILES['userfile']['type'];

 $image_types = Array ("image/bmp",
                        "image/jpeg",
                        "image/pjpeg",
                        "image/gif",
                        "image/x-png");

if (!in_array (strtolower ($userfile_type), $image_types))
    die("File type is not image");

$filename=basename($userfile_name);

if($userfile_size <= 0)
    die("$filename is empty.");

if(!@move_uploaded_file($userfile_tmp_name, "$archive_dir/$filename"))
    die("Can't copy $userfile_name to $filename. $userfile_tmp_name");
if(isset($_ENV['WINDIR']) && !@unlink($userfile))
    die("Can't delete the file $userfile_name");

echo "$filename has been successfully uploaded.<br>";
echo "Filesize : " . number_format($userfile_size) . "<br>";
echo "Filetype : $userfile_type<br>";
}
?>
<?php
if($_POST['action'] =='upload')
{
upload_file();
}else{
upload_form();
}?>

Satya Prakash
  #2 (permalink)  
Old February 2nd, 2006, 03:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

$archive_dir="http://domain_name/images/booksimage/thumb";
is wrong.

Use PHP filesystem functions.

Upload is to your internal directories not to external ones like http://~path~

Hence $archive_dir you're using is wrong.

`~@#\^%&*/\.<.\/-|+|_!:;..=?>
A small donation and a link back to you
Students' finances
  #3 (permalink)  
Old February 3rd, 2006, 08:03 AM
Registered User
 
Join Date: Dec 2005
Location: New Delhi, New Delhi, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spbharti
Default

what is PHP file system functions and what file system function should I use? If you have any idea plz guide me.
  #4 (permalink)  
Old February 3rd, 2006, 08:20 AM
Registered User
 
Join Date: Dec 2005
Location: New Delhi, New Delhi, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spbharti
Default

thanks i did it. thanks alot.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload image-create & save thumbnail-display image angshujit ASP.NET 2.0 Professional 6 July 11th, 2013 10:34 PM
how to upload image? vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 3 June 3rd, 2008 02:53 AM
Upload image phuc2583 Classic ASP Basics 1 January 17th, 2008 08:48 AM
Image upload cutesneakers PHP How-To 2 January 5th, 2005 08:00 AM
Image upload Pallav Javascript How-To 8 October 21st, 2004 12:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.