Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | PHP Help!

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

PHP Help!
Reply
 
Thread Tools
Old 14-03-2005, 13:17   #16
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

yeah sure, although I will have to credit you so PM me your details if you want. In the mean time if I crack it I'll post back here!
Strzelecki is offline   Reply With Quote
Advertisement
Old 14-03-2005, 18:46   #17
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: PHP Help!

As promised, this is the code I use for an image upload script - it's highly cut down because I do a helluva lot more with mine such as working out pixel counts etc (demo here: http://www.richardm.co.uk/gallery/?c...on=Screenshots)
Also, I think this code is an older version than what I'm using now but it should work.

HTML, important bits are marked in bold:
Quote:
<form action="./addimage.php" method="post" enctype="multipart/form-data">
<p>Choose file:</p>
<input type="file" name="ImageUploadedFile" /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
PHP Code:
PHP Code:
// Variables
$ImageDestination = $_POST['ImageDestination'];
$ImageFiletype = $HTTP_POST_FILES['ImageUploadedFile']['type'];
$ImageFilesize = $HTTP_POST_FILES['ImageUploadedFile']['size'];
$ImageUploadedFile = $HTTP_POST_FILES['ImageUploadedFile']['tmp_name'];
$ImageFilename = $HTTP_POST_FILES['ImageUploadedFile']['name'];

// Test Image - nothing allowed apart from jpg, gif and png.
if ($ImageFiletype == 'image/jpeg')
{
$ImageFiletype = 'jpg';
}
elseif (
$ImageFiletype == 'image/gif') {
$ImageFiletype = 'gif';
}
elseif (
$ImageFiletype == 'image/png') {
$ImageFiletype = 'png';
}
else {
echo 
'<html><body><p>The file was not an image!</p></body></html>';
exit;
}

echo 
'<html><body>';

// File handler
if(!is_array ($HTTP_POST_FILES['ImageUploadedFile'])) {
echo 
'<p>A file was not uploaded...<br />';
}
$f =& $HTTP_POST_FILES['ImageUploadedFile']; // saves typing
$dest_dir = "../gallery/" . $ImageDestination;
$dest = $dest_dir . '/'  . $f['name'];
if (!
is_uploaded_file ($f['tmp_name'])) {
echo 
'Error: No file uploaded.<br />';
}
if (!
file_exists ($dest_dir)) {
echo 
"Error: Destination directory $dest_dir does not exist!<br />";
}
if (!
is_dir ($dest_dir)) {
echo 
"Error: Destination directory $dest_dir is not a directory!<br />";
}
if (
file_exists ($dest)) {
echo 
"<html><body>Error: File $dest already exists! I will try to overwrite it...<br />";
}
// all clear, move the file to its permanent location
$r = move_uploaded_file ($f['tmp_name'], $dest);
if (
$r == false)
{ 
// something went wrong
echo "Error: Could not copy file to $dest <br />";
}
else {
echo 
'File uploaded OK...';
}
echo 
'</body></html>'; 
If you want to credit me just link to www.richardm.co.uk - cheers.
Richard M is offline   Reply With Quote
Old 14-03-2005, 20:40   #18
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

Ah thanks for the effort, seen lot of these types of script whilst searching the web, not quite what I want but could be adapted, I really want to know why mine doesn't work though and if anything can be done to fix it. I shall fiddle around with your version though and add my ID loop and see how it goes.
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 21:06   #19
iron25
Inactive
 
Join Date: Aug 2003
Location: nowhere
Posts: 718
iron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful one
Re: PHP Help!

I have had a quick look and it looks like the file is not being written fast enough so by the time it gets to line 29 ($fsize = filesize($dst)) the file can not be found. I can only assume that the processing continues immediately after the line copy($src, $dst) and the OS hasn't written the file yet. That would explain why small files work and large files don't. I've never used the usleep() function before but I can guess that it will act as a pause so either increase this and see what happens.

If it is what I suspect then there are several ways around this:

1. put a loop in to check for the existance of the file before continuing, use the file_exists() function.
2. use the system() function to do the copying. It should then wait for OS to finish processing before it continues processing the script.
3. if all you are after is the file size then you should be able to do something like $fsize = $_FILES['upfile']['size'][$idx] to get the size of the current file.
iron25 is offline   Reply With Quote
Old 14-03-2005, 22:20   #20
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

You're all brilliant! $fsize = $_FILES['upfile']['size'][$idx] seems to have fixed it, don't know why I didn't spot it! So thanks to iron25, Richard M and others, greenies for you all!
I was thinking along the same lines as you iron25 so we must've been right, strange that it happens at exactly 10k, on PHP4 and 5 and on different server setups.
Strzelecki is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:23.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum