Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #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
__________________
Satya Prakash
Reply With Quote
  #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
Reply With Quote
  #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.
Reply With Quote
  #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.
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:34 PM
how to upload image? vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 3 June 3rd, 2008 03: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 01:14 AM



All times are GMT -4. The time now is 04:39 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.