|
|
|
|
Thread title: php upload script problem |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
08-07-2006, 04:30 PM
|
#1
|
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
Posts: 58
|
php upload script problem
I'm creating my own upload script but It won't work
if I want to upload something i get
File '' not uploaded
It's something with the $_FILES i think but don't know how to fix it
PHP Code:
if( isset( $_POST['Upload'] )) {
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "images/";
$MaxFileSize = 800000000;
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetmpname = $_FILES['file']['tmp_name'];
$allowed_types = array( "jpg", "gif", "png" );
$filetype = substr($filename, -3, 3);
//$Thumb = $_POST['Thumbnail'];
//$Water = $_POST['Watermarking'];
if($filename) {
echo 'test';
$error = 0;
if(($filesize > $MaxFileSize) | $filesize = 0 ) {
$error = 1;
$errmsg .= "Your File is to large, (Max File size: 8MB)";
}
if( !in_array( $filetype, $allowed_types )) {
$error = 1;
$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
}else {
$error = 0;
}
if( $error = 1 ) {
die( "$errmsg" );
}else{
$num = rand( 1, 9999 );
$new_filename = $num.$filename;
$upload = move_uploaded_file($filetmpname, "$upload_dir.$new_filename");
if($Thumb = 1 ) {
CreateThumb($filetmpname);
}
if($Water = 1 ) {
CreateWatermark($filetmpname);
}
if( $upload ) {
echo 'Upload Succesfull';
//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
}else {
die( "Cound not upload the file, please try again" );
}
}
}else{
echo "File '$filename' not uploaded";
}
}
?>
|
|
08-07-2006, 04:35 PM
|
#2
|
Status: Request a custom title
Join date: Dec 2005
Location: Colchester, UK
Expertise:
Software:
Posts: 4,625
|
if( !in_array( $_FILE['File']['type'], $allowed_types )) {
Should be:
if( !in_array( $_FILES['file']['type'], $allowed_types )) {
|
|
08-07-2006, 04:46 PM
|
#3
|
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
Posts: 58
|
nope changed that, still the same error.
and
PHP Code:
if($filename) {
echo 'test';
i don't see that eighter
|
|
08-07-2006, 06:22 PM
|
#4
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
Take out the if($filename), it doesn't do anything at all.
|
|
08-07-2006, 06:46 PM
|
#5
|
Status: Senior Member
Join date: Jul 2005
Location:
Expertise:
Software:
Posts: 835
|
I had a quick glance through, and unless PHP has changed since i last dabbed with it,
PHP Code:
if(($filesize > $MaxFileSize) | $filesize = 0 ) {
should be
PHP Code:
if(($filesize > $MaxFileSize) || $filesize == 0 ) {
As in PHP or is || not |, and you're also not checking if the filesize is 0 by using "=" this is the assignment operator, you need ==.
Edit:
You've also done it here:
PHP Code:
if( $error = 1 ) {
make it
PHP Code:
if( $error == 1 ) {
Though I don't see why you're doing it like this, using integers rather than booleans.
|
|
08-07-2006, 07:02 PM
|
#6
|
Status: Member
Join date: Oct 2005
Location: Clifton Park, NY, USA
Expertise:
Software:
Posts: 273
|
Other than the script changes mentioned by the other posters, it would also be helpful to see the form that you're using to submit into the script, to confirm the name of form fields and the encoding type on the form, which may be the other reason you're not seeing the file uploaded.
Mubs
|
|
08-07-2006, 09:38 PM
|
#7
|
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
Posts: 58
|
ok that's the problem right now, I can't go on my computer, It got an error that i'm fixing right now but it takes ages.
I'll post it later
|
|
08-08-2006, 10:54 AM
|
#8
|
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
Posts: 58
|
this is my full code
PHP Code:
<?php
define ('THUMBWIDTH', 100);
define ('THUMBHEIGHT', 100);
function CreateThumb($src) {
copy( $filetmpname, "$upload_dir'.thumb.'$new_filename" );
list($width, $height, $type, $attr) = getimagesize($src);
$img = imagecreatefromstring(file_get_contents($src));
$lowest = min(THUMBWIDTH / $width, THUMBHEIGHT / $height);
if($lowest < 1) {
$smallwidth = floor($lowest*$width);
$smallheight = floor($lowest*$height);
$tmp = imagecreatetruecolor($smallwidth, $smallheight);
imagecopyresized($tmp, $img, 0, 0, 0, 0, $smallwidth, $smallheight, $width, $height);
imagedestroy($img);
$img = $tmp;
}
}
function CreateWatermark($src) {
$img = imagecreatefromstring(file_get_contents($src));
$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
imagestring($img, 5, 3, 3, WATERMARK, $red);
}
if( isset( $_POST['Upload'] )) {
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "images/";
$MaxFileSize = 800000000;
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetmpname = $_FILES['file']['tmp_name'];
$allowed_types = array( "jpg", "gif", "png" );
$filetype = substr($filename, -3, 3);
//$Thumb = $_POST['Thumbnail'];
//$Water = $_POST['Watermarking'];
if($filename) {
echo 'test';
$error = 0;
if(($filesize > $MaxFileSize) | $filesize = 0 ) {
$error = 1;
$errmsg .= "Your File is to large, (Max File size: 8MB)";
}
if( !in_array( $filetype, $allowed_types )) {
$error = 1;
$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
}else {
$error = 0;
}
if( $error = 1 ) {
die( "$errmsg" );
}else{
$num = rand( 1, 9999 );
$new_filename = $num.$filename;
$upload = move_uploaded_file($filetmpname, "$upload_dir.$new_filename");
if($Thumb = 1 ) {
CreateThumb($filetmpname);
}
if($Water = 1 ) {
CreateWatermark($filetmpname);
}
if( $upload ) {
echo 'Upload Succesfull';
//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
}else {
die( "Cound not upload the file, please try again" );
}
}
}else{
echo "File '$filename' not uploaded";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<center>
<script language='JavaScript' type='text/javascript'>
<!--
if (!document.phpAds_used) document.phpAds_used = ',';
phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
document.write ("&what=zone:1&target=_blank");
document.write ("&exclude=" + document.phpAds_used);
if (document.referrer)
document.write ("&referer=" + escape(document.referrer));
document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://x10hosting.com/advert/adclick.php?n=a7fb3e9d' target='_blank'><img src='http://x10hosting.com/advert/adview.php?what=zone:1&n=a7fb3e9d' border='0' alt=''></a></noscript>
<br />
<form action="uploadform.php" method="post">
<input type="file" name="file"><br />
JPG, GIF, PNG uploadable files.<br />
<input type="checkbox" name="Thumbnail"> Thumbnails option<br />
<input type="checkbox" name="Watermarking"> Watermarking option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>
|
|
08-08-2006, 10:58 AM
|
#9
|
Status: Senior Member
Join date: Jul 2005
Location:
Expertise:
Software:
Posts: 835
|
Have you made the fixes I mentioned before? They still stand..
|
|
08-08-2006, 01:57 PM
|
#10
|
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
Posts: 58
|
updated code here
PHP Code:
<?php
define ('THUMBWIDTH', 100);
define ('THUMBHEIGHT', 100);
function CreateThumb($src) {
copy( $filetmpname, "$upload_dir'.thumb.'$new_filename" );
list($width, $height, $type, $attr) = getimagesize($src);
$img = imagecreatefromstring(file_get_contents($src));
$lowest = min(THUMBWIDTH / $width, THUMBHEIGHT / $height);
if($lowest < 1) {
$smallwidth = floor($lowest*$width);
$smallheight = floor($lowest*$height);
$tmp = imagecreatetruecolor($smallwidth, $smallheight);
imagecopyresized($tmp, $img, 0, 0, 0, 0, $smallwidth, $smallheight, $width, $height);
imagedestroy($img);
$img = $tmp;
}
}
function CreateWatermark($src) {
$img = imagecreatefromstring(file_get_contents($src));
$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
imagestring($img, 5, 3, 3, WATERMARK, $red);
}
if( isset( $_POST['Upload'] )) {
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "images/";
$MaxFileSize = 800000000;
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetmpname = $_FILES['file']['tmp_name'];
$allowed_types = array( "jpg", "gif", "png" );
$filetype = substr($filename, -3, 3);
//$Thumb = $_POST['Thumbnail'];
//$Water = $_POST['Watermarking'];
if($filename) {
echo 'test';
$error = 0;
if(($filesize > $MaxFileSize) || $filesize = 0 ) {
$error = 1;
$errmsg .= "Your File is to large, (Max File size: 8MB)";
}
if( !in_array( $filetype, $allowed_types )) {
$error = 1;
$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
}else {
$error = 0;
}
if( $error == 1 ) {
die( "$errmsg" );
}else{
$num = rand( 1, 9999 );
$new_filename = $num.$filename;
$upload = move_uploaded_file($filetmpname, "$upload_dir.$new_filename");
if($Thumb == 1 ) {
CreateThumb($filetmpname);
}
if($Water == 1 ) {
CreateWatermark($filetmpname);
}
if( $upload ) {
echo 'Upload Succesfull';
//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
}else {
die( "Cound not upload the file, please try again" );
}
}
}else{
echo "File '$filename' not uploaded";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<center>
<script language='JavaScript' type='text/javascript'>
<!--
if (!document.phpAds_used) document.phpAds_used = ',';
phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
document.write ("&what=zone:1&target=_blank");
document.write ("&exclude=" + document.phpAds_used);
if (document.referrer)
document.write ("&referer=" + escape(document.referrer));
document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://x10hosting.com/advert/adclick.php?n=a7fb3e9d' target='_blank'><img src='http://x10hosting.com/advert/adview.php?what=zone:1&n=a7fb3e9d' border='0' alt=''></a></noscript>
<br />
<form action="uploadform.php" method="post">
<input type="file" name="file"><br />
JPG, GIF, PNG uploadable files.<br />
<input type="checkbox" name="Thumbnail"> Thumbnails option<br />
<input type="checkbox" name="Watermarking"> Watermarking option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|