hii all
Truly telling i hav got this code from net &
i am finding error while running the code below..
code:- -
<?php
-
$idir = "photo/"; // Path To Images Directory
-
$tdir = "photo/thumbs/"; // Path To Thumbnails Directory
-
$twidth = "125"; // Maximum Width For Thumbnail Images
-
$theight = "100"; // Maximum Height For Thumbnail Images
-
-
if (!isset($_GET['subpage'])) { // Image Upload Form Below ?>
-
<form method="post" action="addphoto.php?subpage=upload" enctype="multipart/form-data">
-
File:<br />
-
<input type="file" name="imagefile" class="form">
-
<br /><br />
-
<input name="submit" type="submit" value="Sumbit" class="form"> <input type="reset" value="Clear" class="form">
-
</form>
-
<? } else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') { // Uploading/Resizing Script
-
$url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use
-
if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
-
$file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
-
$copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location
-
if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location
-
print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image
-
$simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From
-
$currwidth = imagesx($simg); // Current Image Width
-
$currheight = imagesy($simg); // Current Image Height
-
if ($currheight > $currwidth) { // If Height Is Greater Than Width
-
$zoom = $twidth / $currheight; // Length Ratio For Width
-
$newheight = $theight; // Height Is Equal To Max Height
-
$newwidth = $currwidth * $zoom; // Creates The New Width
-
} else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
-
$zoom = $twidth / $currwidth; // Length Ratio For Height
-
$newwidth = $twidth; // Width Is Equal To Max Width
-
$newheight = $currheight * $zoom; // Creates The New Height
-
}
-
$dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail
-
imagetruecolortopalette($simg, false, 256); // Create New Color Pallete
-
$palsize = ImageColorsTotal($simg);
-
for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image
-
$colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used
-
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use
-
}
-
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It)
-
imagejpeg($dimg, "$tdir" . $url); // Saving The Image
-
imagedestroy($simg); // Destroying The Temporary Image
-
imagedestroy($dimg); // Destroying The Other Temporary Image
-
print 'Image thumbnail created successfully.'; // Resize successful
-
} else {
-
print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed
-
}
-
} else {
-
print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is '; // Error Message If Filetype Is Wrong
-
print $file_ext; // Show The Invalid File's Extention
-
print '.</font>';
-
}
-
} ?>
-
error :- -
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.
-
line 18 is $copy=....
anyone can help me i would b grateful..
7 16952
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 :)
Atli 5,058
Expert 4TB
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.
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 -
<?php
-
chmod("/directory/to/chmod", 0755);
-
?>
-
-
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..
Atli 5,058
Expert 4TB
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: -
# An absolute path
-
chmod("/var/www/html/images/image.jpg", 0755);
-
-
# A relative path, assuming the current directory is /var/www/html
-
chmod("images/image.jpg", 0755);
-
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?
Atli 5,058
Expert 4TB
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.
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 ¬_¬
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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 !
...
|
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!!!
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| | |