473,325 Members | 2,480 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,325 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 2838
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
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
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.