473,242 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Photo Upload - Wont work on Linux Server

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
10 2833
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
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
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
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
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
"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tony WONG | last post by:
i am not sure that this subject can be discussed here. i have many photos. they are stored according to the name of the EVENT and YEAR. i will set up a database (sql or access) to store...
3
by: Ken | last post by:
I have a database called autographs.mdb that is in the "XYZ" folder in the "database" folder. I have a form in the database that I want to display a photo of the celeb on. The photos are in a...
5
by: bob garbados | last post by:
I am trying to create a database-driven photo gallery for a friend with an admin form to upload images... I can upload a file to the web server, but I want to store the image in a database and I...
3
by: bob garbados | last post by:
I'm looking for thoughts on photo galleries and security/performance implications... I'm working on an asp.net site in vb that will include an updateable photo gallery that will display thumbnails...
13
by: Viken Karaguesian | last post by:
Hello everyone, Can anyone recommend a good online site to learn PHP? The W3Schools website is quite lacking - leaves much to be desired. I'm sure there are many places, but which ones are good?...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
2
by: RickVidallon | last post by:
I have a .Net application written in C# where members may upload their photos and have them displayed on our website. We are trying to maintain the best quality using best settings in .Net for...
1
by: cumupkid | last post by:
II am trying to create a form that will allow me to upload photos to a folder in the site root directory and add the information to the mysql db at the same time. I have created two forms, one...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.