/    Sign up×
Community /Pin to ProfileBookmark

Php Upload Jpeg Problem..copy Function..

Hello, I have this script that I am trying to get to work! It doesnt seem to upload my file into the directory…the copy function doesnt seem to copy the temporary file into my directory within my site. I read PHP documentation and it seems right! Any suggestions? Here is the code

[code=php]
<?php

if ($HTTP_POST_VARS[‘submit’]) {
print_r($HTTP_POST_FILES);
if (!is_uploaded_file($HTTP_POST_FILES[‘file’][‘tmp_name’])) {
$error = “You did not upload a file!”;
unlink($HTTP_POST_FILES[‘file’][‘tmp_name’]);
// assign error message, remove uploaded file, redisplay form.
} else {
//a file was uploaded
$maxfilesize=102400;

if ($HTTP_POST_FILES[‘file’][‘size’] > $maxfilesize) {
$error = “file is too large”;
unlink($HTTP_POST_FILES[‘file’][‘tmp_name’]);
// assign error message, remove uploaded file, redisplay form.
} else {
if ($HTTP_POST_FILES[‘file’][‘type’] != “image/gif” AND $HTTP_POST_FILES[‘file’][‘type’] != “image/pjpeg”) {
$error = “This file type is not allowed”;
unlink($HTTP_POST_FILES[‘file’][‘tmp_name’]);
// assign error message, remove uploaded file, redisplay form.
} else {
//File has passed all validation, copy it to the final destination and remove the temporary file:
copy($HTTP_POST_FILES[‘file’][‘tmp_name’],”/images/”.$HTTP_POST_FILES[‘file’][‘name’]);
unlink($HTTP_POST_FILES[‘file’][‘tmp_name’]);
print “File has been successfully uploaded!”;
exit;
}
}
}
}
?>

<html>
<head></head>
<body>
<form action=”<?=$PHP_SELF?>” method=”post” enctype=”multipart/form-data”>
<?=$error?>
<br>
Choose a file to upload:<br>
<input type=”file” name=”file”><br>
<input type=”submit” name=”submit” value=”submit”>
</form>
</body>
[/code]

it gives me this message:

[QUOTE]

Array ( [file] => Array ( [name] => Blue hills.jpg [type] => image/pjpeg [tmp_name] => /tmp/phppPcsU3 [error] => 0 [size] => 28521 ) )
Warning: copy(/images/Blue hills.jpg): failed to open stream: Permission denied in /home/content/v/i/c/vicpal25/html/test-area/upload.php on line 24
File has been successfully uploaded!

[/QUOTE]

it gets to my validation of my if & else to say uploaded but nope! it doesnt! my diretory is set to chmod 777! Any suggestions?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@dreamcatcherOct 05.2004 — Have you tried using your full root/server path?

copy($HTTP_POST_FILES['file']['tmp_name'],"/home/public_html/images/".$HTTP_POST_FILES['file']['name']);
Copy linkTweet thisAlerts:
@zachzachOct 06.2004 — try the move_uploaded_file function. BTW, i never figured out how to upload a file bigger than 2 megs no matter what server i was using and what code i tried. oh well. sucks for me ?

move_uploaded_file function ala php.net:

http://us4.php.net/manual/en/function.move-uploaded-file.php
Copy linkTweet thisAlerts:
@ShrineDesignsOct 06.2004 — try this:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
$maxfilesize = 102400;

if($_POST && $_FILES)
{
if(!is_uploaded_file($_FILES['file']['tmp_name']))
{
unlink($_FILES['file']['tmp_name']);
echo "no file was uploaded";
}
else
{
if($_FILES['file']['size'] > $maxfilesize)
{
unlink($_FILES['file']['tmp_name']);
echo "file size is too large";
}
else
{
list(, , $mime) = getimagesize($_FILES['file']['tmp_name']);

if($mime != 2)
{
unlink($_FILES['file']['tmp_name']);
echo "image is not a jpeg";
}
else
{
if(!move_uploaded_file($_FILES['file']['tmp_name'], "images/".$_FILES['file']['name']))
{
unlink($_FILES['file']['tmp_name']);
echo "unable to move uploaded file";
}
else
{
exit("file successfully uploaded");
}
}
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input name="file" type="file" id="file">
<br>
<input name="submit" type="submit" id="submit" value="Submit">
</form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@vicpal25authorOct 06.2004 — it still wont move it onto my server...humm..it gives me this error..


Warning: move_uploaded_file(images/posta.jpg): failed to open stream: No such file or directory in /home/content/v/i/c/vicpal25/html/test-area/upload.php on line 37

Warning: move_uploaded_file(): Unable to move '/tmp/phpXKQg43' to 'images/posta.jpg' in /home/content/v/i/c/vicpal25/html/test-area/upload.php on line 37

unable to move uploaded file

[/QUOTE]


humm..any other suggestions?
×

Success!

Help @vicpal25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...