By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

Photo Upload - Wont work on Linux Server

P: n/a
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??

<?php

include 'gall_settings.inc';

//check if the directory exist or not.
if (!is_dir("$upload_dir"))
{
die ("The directory <b>($upload_dir)</b> doesn't exist");
}

//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("The directory <b>($upload_dir)</b> is NOT writable,
Please Chmod (777)");
}

//Check first if a file has been selected
//is_filetoupload_file('filename') returns true if
//a file was filetoupload via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{
//Get the Size of the File
$size = $_FILES['filetoupload']['size'];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
echo "<b>Error!</b><br>";
echo "File Too Large. Please try again.";
include ('gall_footer.php');
exit();
}

$gallery = $_POST[gallery];

//check if the user has selected photo gallery to upload to.
if ($gallery !== "")
{
switch($gallery)
{
case "01":
echo "Gallery: 01<br>";
break;
case "02":
echo "Gallery: 02<br>";
break;
case "03":
echo "Gallery: 03<br>";
break;
case "04":
echo "Gallery: 04<br>";
break;
case "05":
echo "Gallery: 05<br>";
break;
default:
$gallery = '01';
echo "ERROR: Valid Gallery was not selected.<br>";
echo "File has been saved into Default Gallery: Gallery 01<br><br>";
}
}
else
{
echo "<b>Error!</b><br>";
echo "Please select a valid Gallery:<br>";
include ('gall_footer.php');
exit();
}

// $filename will hold the value of the file name submitted from the form.
// $caption holds the value of the caption for the photo that the user
has written on the form.
$filename = $_FILES['filetoupload']['name'];
$caption = $_POST['caption'];

// strip illegal characters from Filename and Caption
$strippedNam = preg_replace('/[^a-z0-9_., ]/i','',$filename);
$strippedCap = preg_replace('/[^a-z0-9_., ]/i','',$caption);

// Check if file is Already EXISTS.
if(file_exists($upload_dir.$strippedNam)){
echo "<b>Error!</b><br>";
echo "File <b>$strippedNam </b>already exists";
include ('gall_footer.php');
exit();
}

//Move the File to the Directory of your choice
//move_filetoupload_file('filename','destination') Moves an filetoupload
file to a new location.
if
(move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$strippedNam))
{

//tell the user that the file has been uploaded
echo "<b>Upload Complete!</b><br>";
echo "Filename: <a href='$upload_dir$strippedNam'>$strippedNam</a><br>";
echo "Caption: $strippedCap <br><br>";
echo "<a href=/page.php?title=gallery>Go to Public Photo
Gallery</a><br><br>";
include ('gall_footer.php');

// Open captions file in Append mode

$imageFile = $strippedNam;
$captionText = $strippedCap;
// Set the string to be written to the file
$values = "$gallery|$imageFile|$captionText\r\n";

// Open the file for truncated writing
$fp = fopen("$captionFile", "a") or die("Couldn't open data file for
writing!");
$numBytes = fwrite($fp, $values) or die("Couldn't write values to file!");

fclose($fp);
// echo "Wrote $numBytes bytes to data file successfully!";
exit();

}
else
{
//Print error
echo "<b>Error!</b><br>";
echo "There was a problem uploading your file<br>";
echo "Please check the filename and try again.<br>";
include ('gall_footer.php');
exit();

}
}

?>
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
I noticed that Message-ID: <42********@quokka.wn.com.au> from matt
contained the following:
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??


Could be a lot of things. Check the differences between the PHP
versions by using phpinfo() (I recently had a problem with
ver4.3.11-dev)

Check if it works with Firefox instead of IE.

Are GD functions installed?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2

P: n/a
matt wrote:
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??

*snip*

What have you set the error level to in your php.ini? Does perhaps
anything useful appear in your log file?

MfG, Horst
Jul 17 '05 #3

P: n/a
Horst Gutmann wrote:
matt wrote:
I have this code, works perfectly on Windows server, but now i'm
trying to run it on a Linux server, the form submits, i get no errors,
but the photo doesnt upload, and the caption file doesnt write.... any
ideas why??


*snip*

What have you set the error level to in your php.ini? Does perhaps
anything useful appear in your log file?

MfG, Horst

Good point Horst IMHO its best to log all PHP warnings/errors to the
browser client during development/testing. Once the code is moved to a
production area then any problems should be written to logs.
Jul 17 '05 #4

P: n/a
JDS
On Thu, 17 Feb 2005 23:12:36 +1000, matt wrote:
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??


I'm not even going to look at the code and say that the problem is
permissions-related

--
JDS | je*****@go.away.com
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #5

P: n/a
JDS wrote:
On Thu, 17 Feb 2005 23:12:36 +1000, matt wrote:

I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??

I'm not even going to look at the code and say that the problem is
permissions-related

I've checked all permissions, I am testing on the live server as i dont
have a test environment. I use firefox, but it doesnt work in that or IE.
Jul 17 '05 #6

P: n/a
"matt" <mc*****@gmail.com> wrote in message
news:42********@quokka.wn.com.au...
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??

<snip code>
//check if the user has selected photo gallery to upload to.
if ($gallery !== "")
{
switch($gallery)
{
case "01":
echo "Gallery: 01<br>";
break;
case "02":
echo "Gallery: 02<br>";
break;
case "03":
echo "Gallery: 03<br>";
break;
case "04":
echo "Gallery: 04<br>";
break;
case "05":
echo "Gallery: 05<br>";
break;
default:
$gallery = '01';
echo "ERROR: Valid Gallery was not selected.<br>";
echo "File has been saved into Default Gallery: Gallery 01<br><br>";
}
}

<snip rest of code>

You're kidding, right? I'm hoping that you didn't really write out a switch
statement for that. Sure reminds me of a few of the www.thedailywtf.com
examples.
Jul 17 '05 #7

P: n/a
I noticed that Message-ID: <cv**********@athen03.muc.infineon.com> from
Richards Noah (IFR LIT MET) contained the following:
You're kidding, right? I'm hoping that you didn't really write out a switch
statement for that.


Easy tiger. The guy who never wrote dumb code, never wrote code.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

P: n/a

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:kf********************************@4ax.com...
I noticed that Message-ID: <cv**********@athen03.muc.infineon.com> from
Richards Noah (IFR LIT MET) contained the following:
You're kidding, right? I'm hoping that you didn't really write out a
switch
statement for that.


Easy tiger. The guy who never wrote dumb code, never wrote code.


It was pretty scary though <g>

Matt
Jul 17 '05 #9

P: n/a
Richards Noah (IFR LIT MET) wrote:
"matt" <mc*****@gmail.com> wrote in message
news:42********@quokka.wn.com.au...
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??

<snip code>
//check if the user has selected photo gallery to upload to.
if ($gallery !== "")
{
switch($gallery)
{
case "01":
echo "Gallery: 01<br>";
break;
case "02":
echo "Gallery: 02<br>";
break;
case "03":
echo "Gallery: 03<br>";
break;
case "04":
echo "Gallery: 04<br>";
break;
case "05":
echo "Gallery: 05<br>";
break;
default:
$gallery = '01';
echo "ERROR: Valid Gallery was not selected.<br>";
echo "File has been saved into Default Gallery: Gallery 01<br><br>";
}
}


<snip rest of code>

You're kidding, right? I'm hoping that you didn't really write out a switch
statement for that. Sure reminds me of a few of the www.thedailywtf.com
examples.


ease off.. i'm only a beginner... it worked for what i wanted it to
do... if you have a better idea, i'm open to hearing it!
Jul 17 '05 #10

P: n/a
On 2005-02-17 08:12:36 -0500, matt <mc*****@gmail.com> said:
php.ini allow uploads? upload greater than the 2mb default?
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas
why??

<?php

include 'gall_settings.inc';

//check if the directory exist or not.
if (!is_dir("$upload_dir"))
{
die ("The directory <b>($upload_dir)</b> doesn't exist");
}

//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("The directory <b>($upload_dir)</b> is NOT writable,
Please Chmod (777)");
}

//Check first if a file has been selected
//is_filetoupload_file('filename') returns true if
//a file was filetoupload via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{
//Get the Size of the File
$size = $_FILES['filetoupload']['size'];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
echo "<b>Error!</b><br>";
echo "File Too Large. Please try again.";
include ('gall_footer.php');
exit();
}

$gallery = $_POST[gallery];

//check if the user has selected photo gallery to upload to.
if ($gallery !== "")
{
switch($gallery)
{
case "01":
echo "Gallery: 01<br>";
break;
case "02":
echo "Gallery: 02<br>";
break;
case "03":
echo "Gallery: 03<br>";
break;
case "04":
echo "Gallery: 04<br>";
break;
case "05":
echo "Gallery: 05<br>";
break;
default:
$gallery = '01';
echo "ERROR: Valid Gallery was not selected.<br>";
echo "File has been saved into Default Gallery: Gallery 01<br><br>";
}
}
else
{
echo "<b>Error!</b><br>";
echo "Please select a valid Gallery:<br>";
include ('gall_footer.php');
exit();
}

// $filename will hold the value of the file name submitted from the form.
// $caption holds the value of the caption for the photo that the user
has written on the form.
$filename = $_FILES['filetoupload']['name'];
$caption = $_POST['caption'];

// strip illegal characters from Filename and Caption
$strippedNam = preg_replace('/[^a-z0-9_., ]/i','',$filename);
$strippedCap = preg_replace('/[^a-z0-9_., ]/i','',$caption);

// Check if file is Already EXISTS.
if(file_exists($upload_dir.$strippedNam)){
echo "<b>Error!</b><br>";
echo "File <b>$strippedNam </b>already exists";
include ('gall_footer.php');
exit();
}

//Move the File to the Directory of your choice
//move_filetoupload_file('filename','destination') Moves an
filetoupload file to a new location.
if
(move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$strippedNam))
{

//tell the user that the file has been uploaded
echo "<b>Upload Complete!</b><br>";
echo "Filename: <a href='$upload_dir$strippedNam'>$strippedNam</a><br>";
echo "Caption: $strippedCap <br><br>";
echo "<a href=/page.php?title=gallery>Go to Public Photo Gallery</a><br><br>";
include ('gall_footer.php');

// Open captions file in Append mode

$imageFile = $strippedNam;
$captionText = $strippedCap;
// Set the string to be written to the file
$values = "$gallery|$imageFile|$captionText\r\n";

// Open the file for truncated writing
$fp = fopen("$captionFile", "a") or die("Couldn't open data file for
writing!");
$numBytes = fwrite($fp, $values) or die("Couldn't write values to file!");

fclose($fp);
// echo "Wrote $numBytes bytes to data file successfully!";
exit();

}
else
{
//Print error
echo "<b>Error!</b><br>";
echo "There was a problem uploading your file<br>";
echo "Please check the filename and try again.<br>";
include ('gall_footer.php');
exit();

}
}

?>

Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.