View Full Version : I have a problem!
God..
27-10-2007, 09:29 AM
So I am trying to make somthing (upload form)
I got it all working, everything. Just when it upload's it doesn't bring back the file uploaded.
eg what it does here:
http://img135.imageshack.us/img135/4493/uploadaf7.jpg
Insted it brings back this:
It's done! The file has been saved as: /home/cocchic/public_html/upload/upload/9912563351.jpg
How can I bring it back with the URL of the image like this has done?
thanks. + rep/
edit: and bring back an image of it
redtom
27-10-2007, 09:53 AM
Just edit the line of code what displays
saved as: /home/cocchic/public_html/upload/upload/9912563351.jpg
God..
27-10-2007, 09:57 AM
it has '/upload/'
<?php
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
($_FILES["uploaded_file"]["size"] < 350000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/upload/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
}
} else {
echo "Error: Only .jpg images under 350Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
?>
then when I move it i get this:
Warning: move_uploaded_file(/home/cocchic/public_html/uploadhttp://cocchin.com/upload/ad-money.jpg) [function.move-uploaded-file (http://upload.cocchin.com/function.move-uploaded-file)]: failed to open stream: No such file or directory in /home/cocchic/public_html/upload/upload.php on line 14
Warning: move_uploaded_file() [function.move-uploaded-file (http://upload.cocchin.com/function.move-uploaded-file)]: Unable to move '/tmp/php8kGbjE' to '/home/cocchic/public_html/uploadhttp://cocchin.com/upload/ad-money.jpg' in /home/cocchic/public_html/upload/upload.php on line 14
Error: A problem occurred during file upload!
Galaxay1
27-10-2007, 10:04 AM
One i used was
<?
$serverpath = "upload/";
$urltoimages = "URL to the Folder images are stored in";
$maxsize = "500000";
$uniq = uniqid("");
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
echo "Upload file: <input type='file' name='file'>\n";
echo "<br><input type='submit' name='Submit' value='Upload'>\n";
echo "<br>Maximum File Size: $maxsizeb Bytes";
echo "<br>$file";
}
if ($mode == "upload") {
$file = $_FILES['file']['name'];
$name = time() . substr($file, -4);
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "jfef";
$allowedfiles[] = "jpe";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "JFEF";
$allowedfiles[] = "JPE";
$allowedfiles[] = "PNG";
$allowedfiles[] = "PDF";
$allowedfiles[] = "pdf";
$allowedfiles[] = "PSD";
$allowedfiles[] = "psd";
$allowedfiles[] = "bmp";
$allowedfiles[] = "BMP";
$allowedfiles[] = "tif";
$allowedfiles[] = "tiff";
$allowedfiles[] = "TIF";
$allowedfiles[] = "TIFF";
$allowedfiles[] = "dib";
$allowedfiles[] = "DIB";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big";
}
else {
$path = "$serverpath/" . $name;
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
echo "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
echo "<p><img src='$urltoimages/$name' border='0'>";
echo "<p>Direct Link: <input name='direct' type='text' size='75' value='$urltoimages/$name'></a></p>";
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded becuase it is not a recognised image file.</p>"; }
}
}
?>
and it worked fine :P
God..
27-10-2007, 10:05 AM
Works fine +rep
edit:
Forbidden
You don't have permission to access /upload/upload/1193482975.jpg on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.39 Server at Port 80
Now I am getting this
Lycan
27-10-2007, 10:15 AM
problem like you owe people money and refuse to pay up?
One i used was
<?
$serverpath = "upload/";
$urltoimages = "URL to the Folder images are stored in";
$maxsize = "500000";
$uniq = uniqid("");
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
echo "Upload file: <input type='file' name='file'>\n";
echo "<br><input type='submit' name='Submit' value='Upload'>\n";
echo "<br>Maximum File Size: $maxsizeb Bytes";
echo "<br>$file";
}
if ($mode == "upload") {
$file = $_FILES['file']['name'];
$name = time() . substr($file, -4);
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "jfef";
$allowedfiles[] = "jpe";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "JFEF";
$allowedfiles[] = "JPE";
$allowedfiles[] = "PNG";
$allowedfiles[] = "PDF";
$allowedfiles[] = "pdf";
$allowedfiles[] = "PSD";
$allowedfiles[] = "psd";
$allowedfiles[] = "bmp";
$allowedfiles[] = "BMP";
$allowedfiles[] = "tif";
$allowedfiles[] = "tiff";
$allowedfiles[] = "TIF";
$allowedfiles[] = "TIFF";
$allowedfiles[] = "dib";
$allowedfiles[] = "DIB";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big";
}
else {
$path = "$serverpath/" . $name;
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
echo "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
echo "<p><img src='$urltoimages/$name' border='0'>";
echo "<p>Direct Link: <input name='direct' type='text' size='75' value='$urltoimages/$name'></a></p>";
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded becuase it is not a recognised image file.</p>"; }
}
}
?>
and it worked fine :P
Removed copyright from original maker? :(
Galaxay1
27-10-2007, 05:18 PM
I didnt copy anyone i used some guide then edited it :P however the original can be found in tutorials thread :P I did copy the main from it then edited it :)
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.