Connecting Tech Pros Worldwide Help | Site Map

Photo Upload - Wont work on Linux Server

matt
Guest
 
Posts: n/a
#1: Jul 17 '05
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();

}
}

?>
Geoff Berrow
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


I noticed that Message-ID: <42149916$1@quokka.wn.com.au> from matt
contained the following:
[color=blue]
>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??[/color]

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/
Horst Gutmann
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


matt wrote:[color=blue]
> 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??[/color]
*snip*

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

MfG, Horst
noSpam
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


Horst Gutmann wrote:[color=blue]
> matt wrote:
>[color=green]
>> 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??[/color]
>
> *snip*
>
> What have you set the error level to in your php.ini? Does perhaps
> anything useful appear in your log file?
>
> MfG, Horst[/color]
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.
JDS
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


On Thu, 17 Feb 2005 23:12:36 +1000, matt wrote:
[color=blue]
> 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??[/color]

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

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

matt
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


JDS wrote:[color=blue]
> On Thu, 17 Feb 2005 23:12:36 +1000, matt wrote:
>
>[color=green]
>>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??[/color]
>
>
> I'm not even going to look at the code and say that the problem is
> permissions-related
>[/color]
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.
Richards Noah \(IFR LIT MET\)
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


"matt" <mcpaton@gmail.com> wrote in message
news:42149916$1@quokka.wn.com.au...[color=blue]
> 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??
>[/color]

<snip code>
[color=blue]
> //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>";
> }
> }[/color]
<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.


Geoff Berrow
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


I noticed that Message-ID: <cv5lj3$kec$1@athen03.muc.infineon.com> from
Richards Noah (IFR LIT MET) contained the following:
[color=blue]
>You're kidding, right? I'm hoping that you didn't really write out a switch
>statement for that.[/color]

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/
Matt Mitchell
Guest
 
Posts: n/a
#9: Jul 17 '05

re: Photo Upload - Wont work on Linux Server



"Geoff Berrow" <blthecat@ckdog.co.uk> wrote in message
news:kfpc1158590h9bfa7fm2c6prfnke2ajfdv@4ax.com...[color=blue]
>I noticed that Message-ID: <cv5lj3$kec$1@athen03.muc.infineon.com> from
> Richards Noah (IFR LIT MET) contained the following:
>[color=green]
>>You're kidding, right? I'm hoping that you didn't really write out a
>>switch
>>statement for that.[/color]
>
> Easy tiger. The guy who never wrote dumb code, never wrote code.
>[/color]

It was pretty scary though <g>

Matt


matt
Guest
 
Posts: n/a
#10: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


Richards Noah (IFR LIT MET) wrote:[color=blue]
> "matt" <mcpaton@gmail.com> wrote in message
> news:42149916$1@quokka.wn.com.au...
>[color=green]
>>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??
>>[/color]
>
>
> <snip code>
>[color=green]
>>//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>";
>>}
>>}[/color]
>
> <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.
>
>[/color]

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!
Frank East
Guest
 
Posts: n/a
#11: Jul 17 '05

re: Photo Upload - Wont work on Linux Server


On 2005-02-17 08:12:36 -0500, matt <mcpaton@gmail.com> said:
php.ini allow uploads? upload greater than the 2mb default?
[color=blue]
> 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();
>
> }
> }
>
> ?>[/color]


Closed Thread