473,704 Members | 6,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php image upload ,resize &making thumbnail

23 New Member
hii all
Truly telling i hav got this code from net &
i am finding error while running the code below..

code:-
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $idir = "photo/";   // Path To Images Directory
  3. $tdir = "photo/thumbs/";   // Path To Thumbnails Directory
  4. $twidth = "125";   // Maximum Width For Thumbnail Images
  5. $theight = "100";   // Maximum Height For Thumbnail Images
  6.  
  7. if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?>
  8.   <form method="post" action="addphoto.php?subpage=upload" enctype="multipart/form-data">
  9.    File:<br />
  10.   <input type="file" name="imagefile" class="form">
  11.   <br /><br />
  12.   <input name="submit" type="submit" value="Sumbit" class="form">  <input type="reset" value="Clear" class="form">
  13.   </form>
  14. <? } else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script
  15.   $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use
  16.   if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
  17.     $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
  18.     $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location
  19.     if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
  20.       print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image
  21.       $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From
  22.       $currwidth = imagesx($simg);   // Current Image Width
  23.       $currheight = imagesy($simg);   // Current Image Height
  24.       if ($currheight > $currwidth) {   // If Height Is Greater Than Width
  25.          $zoom = $twidth / $currheight;   // Length Ratio For Width
  26.          $newheight = $theight;   // Height Is Equal To Max Height
  27.          $newwidth = $currwidth * $zoom;   // Creates The New Width
  28.       } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
  29.         $zoom = $twidth / $currwidth;   // Length Ratio For Height
  30.         $newwidth = $twidth;   // Width Is Equal To Max Width
  31.         $newheight = $currheight * $zoom;   // Creates The New Height
  32.       }
  33.       $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
  34.       imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
  35.       $palsize = ImageColorsTotal($simg);
  36.       for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
  37.        $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
  38.        ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
  39.       }
  40.       imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
  41.       imagejpeg($dimg, "$tdir" . $url);   // Saving The Image
  42.       imagedestroy($simg);   // Destroying The Temporary Image
  43.       imagedestroy($dimg);   // Destroying The Other Temporary Image
  44.       print 'Image thumbnail created successfully.';   // Resize successful
  45.     } else {
  46.       print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed
  47.     }
  48.   } else {
  49.     print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong
  50.     print $file_ext;   // Show The Invalid File's Extention
  51.     print '.</font>';
  52.   }
  53. } ?>
  54.  
error :-
Expand|Select|Wrap|Line Numbers
  1. Warning: copy(photo/DSC00031.JPG): failed to open stream: Permission denied in /hsphere/local/home/wwwuser/home.mishra.biz/addphoto.php on line 18 ERROR: Unable to upload image.
  2.  
line 18 is $copy=....

anyone can help me i would b grateful..
Nov 21 '07 #1
7 17055
Markus
6,050 Recognized Expert Expert
Sounds like you dont have the right file permissions set.

You need to chmod the directory to a more appropriate level!
[php]
<?php
chmod("/directory/to/chmod", 0755);
?>
[/php]

Lemme know if this helps!

Also! Remember to wrap your php code in the CODE tags.

IT helps people look through your code :)
Nov 21 '07 #2
Atli
5,058 Recognized Expert Expert
Hi.

Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thank you.
Nov 21 '07 #3
mishrarajesh44
23 New Member
Sounds like you dont have the right file permissions set.

You need to chmod the directory to a more appropriate level!
[php]
<?php
chmod("/directory/to/chmod", 0755);
?>
[/php]

Lemme know if this helps!

Also! Remember to wrap your php code in the CODE tags.

IT helps people look through your code :)
i hav executed the code u said
Expand|Select|Wrap|Line Numbers
  1.       <?php
  2.       chmod("/directory/to/chmod", 0755);
  3.         ?>
  4.  
  5.  
but it gives error , i replaced 'directory' by 'photo' the folder i hav created to store uploaded photo..but still it is giving error

see the error:-

Warning: chmod(): No such file or directory in /local/home/wwwuser/home.mishra.biz/chmod.php on line 2


please tell me what else to do..
i need the solution soon..
if u can i will be obliged..
Nov 23 '07 #4
Atli
5,058 Recognized Expert Expert
How exactly did the path you use look?

If you want to use a relative path, a path relative to the current directory, there should not be a / in front of it.

On the other hand, if you are using an absolute path, a path relative to the root directory, you should put a / in front of it.

Like:
Expand|Select|Wrap|Line Numbers
  1. # An absolute path
  2. chmod("/var/www/html/images/image.jpg", 0755);
  3.  
  4. # A relative path, assuming the current directory is /var/www/html
  5. chmod("images/image.jpg", 0755);
  6.  
Nov 23 '07 #5
Markus
6,050 Recognized Expert Expert
It's not the image he's wanting to chmod() is it?

Am i right in thinking he would also need to chmod the php file that is executing? i.e. the uploader script aswell as the actual directory where the images would be stored? Or is that not necessary?
Nov 23 '07 #6
Atli
5,058 Recognized Expert Expert
It's not the image he's wanting to chmod() is it?

Am i right in thinking he would also need to chmod the php file that is executing? i.e. the uploader script aswell as the actual directory where the images would be stored? Or is that not necessary?
It doesn't really matter whether it is a file or a directory. All directories in a Linux system are essentially files anyways so the chmod command works the same on both.

He would not have to chmod the PHP file that is being executed, only the file or directory he intends to change.

The user running the HTTP server only needs read and execute permission on the PHP file to be able to execute it, but it needs write permission on the file the PHP script is meant to change.
Nov 24 '07 #7
Markus
6,050 Recognized Expert Expert
It doesn't really matter whether it is a file or a directory. All directories in a Linux system are essentially files anyways so the chmod command works the same on both.

He would not have chmod the PHP file that is being executed, only the file or directory he intends to change.

The user running the HTTP server only needs read and execute permission on the PHP file to be able to execute it, but it needs write permission on the file the PHP script is meant to change.
Oh i see.

I wonder how (s)he's getting along with it ¬_¬
Nov 24 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1726
by: Paul | last post by:
Hi, I am writing an ASP site that contains images. The owner of the site wants to be able to upload images. The only problem is that the owner is not computer literate enough to be able to create a thumbnail. So basically I am looking for some code that would help me take the image he has and create a thumbnail out of the image. I am sure this could be a complex process, but I figured this would be a good place to start.
1
2281
by: manish | last post by:
Hi, I am a fresher in the programming field i.e although I have done programming at the basic level but at professional level I am very new and I am facing many problems. These probllems are not taughtand I am not getting any Refrences to cope with them. ********Setting in VC++ 6.0 I don'know to apply setting for various/different projects. I am not getting basics out of it .Can u pls tell me how to make a good understanding of...
8
4813
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions:
2
4582
by: Mark R. Dawson | last post by:
Hi all, I have a directory full of images (most over 2MB in size) I was to show each image as a thumbnail on a form, however in order to create a thumbnail I have to open the complete image then scale it down. This is quite slow, since there is a lot of file IO going on, what I want to be able to do is open the image in the scaled down size so that I miss out the step of opening the file then dowsizing it. I have not been able to find...
6
1739
by: Trint Smith | last post by:
How can I show image thumbnail?? thanks, Trint ..Net programmer trintsmith@hotmail.com *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
5
2578
by: sp_mclaugh | last post by:
Hi. I've just recently switched to using CSS (rather than tables) to display collections of thumbnails. That way, depending on the user's screen resolution and browser window size, the number of "columns" on the window is variable. Some examples of pages I've created this way are: http://www.engr.uconn.edu/~spm01f01/suspension/ http://www.engr.uconn.edu/~spm01f01/tutorial/
2
1803
by: Michiel Sikma | last post by:
Hello everybody. I'm currently involved in a site building project in which we're going to use the Google Maps API. The user will be able to browse the site by looking over a really large image, similar to how Google Maps itself works, except with the design of the site on the background rather than a map of the world. I initially hired someone to do it in PHP (don't bite, please :-) but it seems that I forgot about one thing: the...
1
3136
by: dodgeyb | last post by:
Hi there, Trying to allow client to upload image, thumbnail it, and save it into sql table image field. Code compiles & runs but image cannot be retrieved. any clues what I'm doing wrong pls ! Dim origImage As System.Drawing.Image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
1
1470
by: karanmymatrix | last post by:
Req Code For Horizontal Bar Attach To Image Thumbnail. With Every Change In Horizontal Bar ,it Scroll To New Image In Thumbnaiil !!! Plz Give Code For Same As Early As Possible!!!
0
8766
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9134
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7885
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3132
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2474
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.